{"action":"created","issue":{"url":"https://api.github.com/repos/facebook/flow/issues/3367","repository_url":"https://api.github.com/repos/facebook/flow","labels_url":"https://api.github.com/repos/facebook/flow/issues/3367/labels{/name}","comments_url":"https://api.github.com/repos/facebook/flow/issues/3367/comments","events_url":"https://api.github.com/repos/facebook/flow/issues/3367/events","html_url":"https://github.com/facebook/flow/issues/3367","id":206947106,"number":3367,"title":"$Pick utility type","user":{"login":"mgtitimoli","id":4404683,"avatar_url":"https://avatars2.githubusercontent.com/u/4404683?v=4","gravatar_id":"","url":"https://api.github.com/users/mgtitimoli","html_url":"https://github.com/mgtitimoli","followers_url":"https://api.github.com/users/mgtitimoli/followers","following_url":"https://api.github.com/users/mgtitimoli/following{/other_user}","gists_url":"https://api.github.com/users/mgtitimoli/gists{/gist_id}","starred_url":"https://api.github.com/users/mgtitimoli/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mgtitimoli/subscriptions","organizations_url":"https://api.github.com/users/mgtitimoli/orgs","repos_url":"https://api.github.com/users/mgtitimoli/repos","events_url":"https://api.github.com/users/mgtitimoli/events{/privacy}","received_events_url":"https://api.github.com/users/mgtitimoli/received_events","type":"User","site_admin":false},"labels":[{"id":149548105,"url":"https://api.github.com/repos/facebook/flow/labels/feature%20request","name":"feature request","color":"d4c5f9","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2017-02-11T01:38:47Z","updated_at":"2017-11-16T20:46:47Z","closed_at":null,"author_association":"NONE","body":"Hi there,\r\n\r\nI've just came across with the need of defining an object type using a subset of another, or in other words, use some props definition of a certain object type and intersect this result (a reduced object type) with another set of props definitions to define a new type.\r\n\r\nI used to do this a lot with PropTypes using pick utility from lodash, but we've recently moved to flow and I really miss this functionality, so I was wondering if you have ever thought of the possibility of adding a `$Pick` utility type to be able to do something like the following:\r\n\r\n```javascript\r\n// @flow\r\n\r\ntype O1 = {\r\n  o1k1: string,\r\n  o1k2: number,\r\n  o1k3: boolean,\r\n};\r\n\r\n// o1k1 and o1k2 mandatory\r\ntype O2 = $Pick<O1, o1k1 & o1k2> & {\r\n  o2k1: () => void,\r\n  o2k2: Date,\r\n};\r\n\r\n// o1k1 and o1k2 optional\r\ntype O2 = $Pick<O1, ?o1k1 & ?o1k2> & {\r\n  o2k1: () => void,\r\n  o2k2: Date,\r\n};\r\n```\r\n\r\nRight now I partially dealing with this using `$Shape` like the following, but this doesn't restrict additional props I don't want to, neither it let me mark any of them as required\r\n\r\n```javascript\r\n// @flow\r\n\r\ntype O1 = {\r\n  o1k1: string,\r\n  o1k2: number,\r\n  o1k3: boolean,\r\n};\r\n\r\ntype O2 = $Shape<O1> & {\r\n  o2k1: () => void,\r\n  o2k2: Date,\r\n};\r\n```"},"comment":{"url":"https://api.github.com/repos/facebook/flow/issues/comments/345057278","html_url":"https://github.com/facebook/flow/issues/3367#issuecomment-345057278","issue_url":"https://api.github.com/repos/facebook/flow/issues/3367","id":345057278,"user":{"login":"Andarist","id":9800850,"avatar_url":"https://avatars2.githubusercontent.com/u/9800850?v=4","gravatar_id":"","url":"https://api.github.com/users/Andarist","html_url":"https://github.com/Andarist","followers_url":"https://api.github.com/users/Andarist/followers","following_url":"https://api.github.com/users/Andarist/following{/other_user}","gists_url":"https://api.github.com/users/Andarist/gists{/gist_id}","starred_url":"https://api.github.com/users/Andarist/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Andarist/subscriptions","organizations_url":"https://api.github.com/users/Andarist/orgs","repos_url":"https://api.github.com/users/Andarist/repos","events_url":"https://api.github.com/users/Andarist/events{/privacy}","received_events_url":"https://api.github.com/users/Andarist/received_events","type":"User","site_admin":false},"created_at":"2017-11-16T20:46:47Z","updated_at":"2017-11-16T20:46:47Z","author_association":"NONE","body":"This would be super cool, especially if we could pass to `$Pick`/`$Omit` `$Keys`'s output.\r\n\r\nSomething like:\r\n```js\r\nconst omit = <T: Object, K: $Keys<T>>(keys: K[], obj: T): $Omit<T, K> =>\r\n  Object.keys(obj)\r\n    .filter(key => keys.indexOf(key) === -1)\r\n    .reduce((result, key) => {\r\n      result[key] = obj[key]\r\n      return result\r\n  }, {})\r\n```"}}
{"actor":{"display_login":"Andarist"}}