{"action":"created","issue":{"url":"https://api.github.com/repos/facebook/flow/issues/187","labels_url":"https://api.github.com/repos/facebook/flow/issues/187/labels{/name}","comments_url":"https://api.github.com/repos/facebook/flow/issues/187/comments","events_url":"https://api.github.com/repos/facebook/flow/issues/187/events","html_url":"https://github.com/facebook/flow/issues/187","id":51856472,"number":187,"title":"Mixing map annotations with other properties","user":{"login":"crm416","id":1309177,"avatar_url":"https://avatars.githubusercontent.com/u/1309177?v=3","gravatar_id":"","url":"https://api.github.com/users/crm416","html_url":"https://github.com/crm416","followers_url":"https://api.github.com/users/crm416/followers","following_url":"https://api.github.com/users/crm416/following{/other_user}","gists_url":"https://api.github.com/users/crm416/gists{/gist_id}","starred_url":"https://api.github.com/users/crm416/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/crm416/subscriptions","organizations_url":"https://api.github.com/users/crm416/orgs","repos_url":"https://api.github.com/users/crm416/repos","events_url":"https://api.github.com/users/crm416/events{/privacy}","received_events_url":"https://api.github.com/users/crm416/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/facebook/flow/labels/enhancement","name":"enhancement","color":"84b6eb"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2014-12-12T21:42:57Z","updated_at":"2015-05-15T21:21:12Z","closed_at":null,"body":"I may not have a great understanding of how the [objects-as-maps](http://flowtype.org/docs/objects.html#objects-as-maps) type system should work, but it's strange to me that Flow lets you add map-violating properties to an object literal at time of creation, only to throw an error when you attempt to read from it.\r\n\r\nFor example:\r\n```js\r\nvar numToString: { [key:number]: string} = {\r\n  foo: 'bar' // no error here, even though the key is not a number\r\n};\r\nnumToString.foo; // throws an error because the key is a string\r\nnumToString['foo']; // throws an error because the key is a string\r\n```\r\n\r\nYou get the same behavior if you include the property in the type annotation:\r\n\r\n```js\r\nvar numToString: { foo: string; [key:number]: string} = {\r\n  foo: 'bar' // no error here\r\n};\r\nnumToString.foo; // throws an error\r\nnumToString['foo']; // throws an error\r\n```\r\n\r\nWith the current behavior, the only reason I can think of to allow mixing map annotations and specific-property annotations would be to mark some keys as required, and that would only work (as-is) if you're using a map from strings to something else.\r\n\r\nIntuitively, my guess is that my first example should throw an error at the time of creation, but that my second should work throughout (i.e., adding specific-property annotations is way of white-list properties that don't adhere to the overall map type)."},"comment":{"url":"https://api.github.com/repos/facebook/flow/issues/comments/102528166","html_url":"https://github.com/facebook/flow/issues/187#issuecomment-102528166","issue_url":"https://api.github.com/repos/facebook/flow/issues/187","id":102528166,"user":{"login":"samwgoldman","id":254842,"avatar_url":"https://avatars.githubusercontent.com/u/254842?v=3","gravatar_id":"","url":"https://api.github.com/users/samwgoldman","html_url":"https://github.com/samwgoldman","followers_url":"https://api.github.com/users/samwgoldman/followers","following_url":"https://api.github.com/users/samwgoldman/following{/other_user}","gists_url":"https://api.github.com/users/samwgoldman/gists{/gist_id}","starred_url":"https://api.github.com/users/samwgoldman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/samwgoldman/subscriptions","organizations_url":"https://api.github.com/users/samwgoldman/orgs","repos_url":"https://api.github.com/users/samwgoldman/repos","events_url":"https://api.github.com/users/samwgoldman/events{/privacy}","received_events_url":"https://api.github.com/users/samwgoldman/received_events","type":"User","site_admin":false},"created_at":"2015-05-15T21:21:12Z","updated_at":"2015-05-15T21:21:12Z","body":"My understanding is that it only make sense for keys to be `string`, so the `{ [key: number]: string }` type is not really worth supporting. In fact, I'd argue that providing a syntax to specify key types isn't very sensible."}}