{"action":"created","issue":{"url":"https://api.github.com/repos/facebook/flow/issues/5276","repository_url":"https://api.github.com/repos/facebook/flow","labels_url":"https://api.github.com/repos/facebook/flow/issues/5276/labels{/name}","comments_url":"https://api.github.com/repos/facebook/flow/issues/5276/comments","events_url":"https://api.github.com/repos/facebook/flow/issues/5276/events","html_url":"https://github.com/facebook/flow/issues/5276","id":271336439,"node_id":"MDU6SXNzdWUyNzEzMzY0Mzk=","number":5276,"title":"Better support for object types with union types indexer keys","user":{"login":"eloytoro","id":3936773,"node_id":"MDQ6VXNlcjM5MzY3NzM=","avatar_url":"https://avatars0.githubusercontent.com/u/3936773?v=4","gravatar_id":"","url":"https://api.github.com/users/eloytoro","html_url":"https://github.com/eloytoro","followers_url":"https://api.github.com/users/eloytoro/followers","following_url":"https://api.github.com/users/eloytoro/following{/other_user}","gists_url":"https://api.github.com/users/eloytoro/gists{/gist_id}","starred_url":"https://api.github.com/users/eloytoro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eloytoro/subscriptions","organizations_url":"https://api.github.com/users/eloytoro/orgs","repos_url":"https://api.github.com/users/eloytoro/repos","events_url":"https://api.github.com/users/eloytoro/events{/privacy}","received_events_url":"https://api.github.com/users/eloytoro/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":20,"created_at":"2017-11-06T01:43:45Z","updated_at":"2018-07-20T14:41:20Z","closed_at":null,"author_association":"NONE","body":"## Flexible types\r\n\r\n```js\r\ntype Key = 'xs' | 'sm'\r\ntype Value = { [Key]: number }\r\n```\r\n\r\nRight now flow will complain if you try to define an object that contains **less** properties than its defined type allows it to have, however this is not the case for types that have a indexer key defined for an enum.\r\n\r\nIn most typed languages enums should always be exhausted, however flow seems to ignore this by allowing _less_ keys to be present in the object, which goes against the specified behavior for non-strict object types.\r\n\r\n### Solution\r\n\r\n* Make flow check for the presence of all of the keys of enums when these are statically defined.\r\n* Do not type check keys that are not present in the object definition or the enum\r\n\r\n### Special cases\r\n\r\nThe case where the enum both statically and generically defined\r\n\r\n```\r\ntype Key = 'xs' | string\r\n```\r\n\r\nHere all we have to do is to take the most general case (string) and ignore the static definitions\r\n\r\n## Exact types\r\n\r\n```js\r\ntype Key = 'xs' | 'sm'\r\ntype Value = {| [Key]: number |}\r\n```\r\n\r\nRight now flow just doesnt really know what to do here, I don't think there's a single object that matches this type, while it looks pretty well defined, flow disagrees\r\n\r\n### Solution\r\n\r\nIn the example above the `Value` type could behave as a \"key comprehension\" of the `Key` union type in a way that it makes sure that the object has *only keys defined by the union type, no more, no less*\r\n\r\n### Special cases\r\n\r\nBasically any general types should throw an error eagerly for trying to define all of the keys of an object generically. I.e.\r\n\r\n```\r\n{| [string]: number |} // this object has all the possible string keys EVER\r\n```\r\n\r\n## Advantages\r\n\r\nNow that we know which keys are in the object, calling `Object.keys` should return the `$Keys` of its argument\r\n\r\nTL;DR The example is pretty self explanatory:\r\n\r\nhttps://flow.org/try/#0PTAEAEDMBsHsHcBQBLAtgB1gJwC6gEoCmAhgMZ6RayqgDkWJ5tA3IojgJ7qGgDShHUAF46ADwDOtUAB8641LTalYAO3F5YAIwBWABgBcoAN6yA2vw4BdQyoCuqTYSwyAvsOOgJhgMyg3IUHEAC1hbaAATUCcqZ0hsUFRkcXFkFQBzUABrAVAAA3lcxGU1DR0ARkMTUHMBa1A7BydXdyNPcR8AGkDUQwAWP1AA4NCI+tg8aOwi1XVQLW0AJkrqizqGx2c3EVavUF9-MGGwyMnY+MTk1IzswXzUQuLZ+e9lmqsbew2B7dA42B8BkMQscxhMsDEgA"},"comment":{"url":"https://api.github.com/repos/facebook/flow/issues/comments/406621372","html_url":"https://github.com/facebook/flow/issues/5276#issuecomment-406621372","issue_url":"https://api.github.com/repos/facebook/flow/issues/5276","id":406621372,"node_id":"MDEyOklzc3VlQ29tbWVudDQwNjYyMTM3Mg==","user":{"login":"eloytoro","id":3936773,"node_id":"MDQ6VXNlcjM5MzY3NzM=","avatar_url":"https://avatars0.githubusercontent.com/u/3936773?v=4","gravatar_id":"","url":"https://api.github.com/users/eloytoro","html_url":"https://github.com/eloytoro","followers_url":"https://api.github.com/users/eloytoro/followers","following_url":"https://api.github.com/users/eloytoro/following{/other_user}","gists_url":"https://api.github.com/users/eloytoro/gists{/gist_id}","starred_url":"https://api.github.com/users/eloytoro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eloytoro/subscriptions","organizations_url":"https://api.github.com/users/eloytoro/orgs","repos_url":"https://api.github.com/users/eloytoro/repos","events_url":"https://api.github.com/users/eloytoro/events{/privacy}","received_events_url":"https://api.github.com/users/eloytoro/received_events","type":"User","site_admin":false},"created_at":"2018-07-20T14:41:20Z","updated_at":"2018-07-20T14:41:20Z","author_association":"NONE","body":"That doesn't compile"}}
{"actor":{"display_login":"eloytoro"}}