{"action":"created","issue":{"url":"https://api.github.com/repos/dubzzz/fast-check/issues/71","repository_url":"https://api.github.com/repos/dubzzz/fast-check","labels_url":"https://api.github.com/repos/dubzzz/fast-check/issues/71/labels{/name}","comments_url":"https://api.github.com/repos/dubzzz/fast-check/issues/71/comments","events_url":"https://api.github.com/repos/dubzzz/fast-check/issues/71/events","html_url":"https://github.com/dubzzz/fast-check/issues/71","id":312786466,"number":71,"title":"`record` could preserve more type information","user":{"login":"amonks","id":50010,"avatar_url":"https://avatars0.githubusercontent.com/u/50010?v=4","gravatar_id":"","url":"https://api.github.com/users/amonks","html_url":"https://github.com/amonks","followers_url":"https://api.github.com/users/amonks/followers","following_url":"https://api.github.com/users/amonks/following{/other_user}","gists_url":"https://api.github.com/users/amonks/gists{/gist_id}","starred_url":"https://api.github.com/users/amonks/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amonks/subscriptions","organizations_url":"https://api.github.com/users/amonks/orgs","repos_url":"https://api.github.com/users/amonks/repos","events_url":"https://api.github.com/users/amonks/events{/privacy}","received_events_url":"https://api.github.com/users/amonks/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-04-10T06:17:50Z","updated_at":"2018-04-10T18:42:21Z","closed_at":null,"author_association":"NONE","body":"Currently, Record drops type information about the individual properties in recordModel.\r\n\r\nFor example, let's say Users have two properties:\r\n\r\n```typescript\r\ninterface User {\r\n  name: string;\r\n  age: number;\r\n}\r\n```\r\n\r\nIf I'd like to use fast-check to generate this record, I must type it like this:\r\n\r\n```typescript\r\nfc.record<string | number>({\r\n  name: fc.string(),\r\n  age: fc.integer(),\r\n});\r\n```\r\n\r\nThe resultant object has the type `{ [k: string]: string | number }`, not the type `User`.\r\n\r\nRecord would be more powerful if it could be used like this:\r\n\r\n```typescript\r\nfc.record<User>({\r\n  name: fc.string(),\r\n  age: fc.integer(),\r\n});\r\n```\r\n\r\nIt could achieve that with a declaration using mapped types, like this:\r\n\r\n```typescript\r\ndeclare function record<T>(recordModel: {\r\n  [K in keyof T]: Arbitrary<T[K]>;\r\n}): Arbitrary<{\r\n  [K in keyof T]: T[K];\r\n}>;\r\n```\r\n\r\nGoing even further, it could capture the result of calling with with_deleted_keys set to `true` as the mapped type `Partial<T>`, using the conditional type operator:\r\n\r\n```typescript\r\nexport interface RecordConstraints { \r\n  with_deleted_keys?: boolean \r\n}\r\ninterface RecordConstraintsWithDeletedKeys {\r\n  with_deleted_keys: true\r\n}\r\n\r\ndeclare function record<T>(\r\n  recordModel: {\r\n    [K in keyof T]: Arbitrary<T[K]>;\r\n  },\r\n  constraints?: RecordConstraints,\r\n): Arbitrary<\r\n  RecordConstraints extends RecordConstraintsWithDeletedKeys \r\n    ? { [K in keyof T]: T[K] } \r\n    : Partial<{[K in keyof T]: T[K]}>\r\n>;\r\n```\r\n\r\nIf you'd like, I can work on a PR for either or both of these changes."},"comment":{"url":"https://api.github.com/repos/dubzzz/fast-check/issues/comments/380205971","html_url":"https://github.com/dubzzz/fast-check/issues/71#issuecomment-380205971","issue_url":"https://api.github.com/repos/dubzzz/fast-check/issues/71","id":380205971,"user":{"login":"dubzzz","id":5300235,"avatar_url":"https://avatars1.githubusercontent.com/u/5300235?v=4","gravatar_id":"","url":"https://api.github.com/users/dubzzz","html_url":"https://github.com/dubzzz","followers_url":"https://api.github.com/users/dubzzz/followers","following_url":"https://api.github.com/users/dubzzz/following{/other_user}","gists_url":"https://api.github.com/users/dubzzz/gists{/gist_id}","starred_url":"https://api.github.com/users/dubzzz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dubzzz/subscriptions","organizations_url":"https://api.github.com/users/dubzzz/orgs","repos_url":"https://api.github.com/users/dubzzz/repos","events_url":"https://api.github.com/users/dubzzz/events{/privacy}","received_events_url":"https://api.github.com/users/dubzzz/received_events","type":"User","site_admin":false},"created_at":"2018-04-10T18:42:21Z","updated_at":"2018-04-10T18:42:21Z","author_association":"OWNER","body":"Indeed I struggled to find a way to achieve that easily. It would be very nice to have it. \n\nAs you want for the fix. Either you can do it and issue a pr or I can handle it on my side. "}}
{"actor":{"display_login":"dubzzz"}}