{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/12289","repository_url":"https://api.github.com/repos/Microsoft/TypeScript","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/12289/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/12289/comments","events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/12289/events","html_url":"https://github.com/Microsoft/TypeScript/issues/12289","id":189587745,"number":12289,"title":"Unsimpilifed Interesction Types Prevent Type Inference","user":{"login":"ethanresnick","id":471894,"avatar_url":"https://avatars.githubusercontent.com/u/471894?v=3","gravatar_id":"","url":"https://api.github.com/users/ethanresnick","html_url":"https://github.com/ethanresnick","followers_url":"https://api.github.com/users/ethanresnick/followers","following_url":"https://api.github.com/users/ethanresnick/following{/other_user}","gists_url":"https://api.github.com/users/ethanresnick/gists{/gist_id}","starred_url":"https://api.github.com/users/ethanresnick/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ethanresnick/subscriptions","organizations_url":"https://api.github.com/users/ethanresnick/orgs","repos_url":"https://api.github.com/users/ethanresnick/repos","events_url":"https://api.github.com/users/ethanresnick/events{/privacy}","received_events_url":"https://api.github.com/users/ethanresnick/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2016-11-16T04:47:27Z","updated_at":"2016-11-17T01:52:26Z","closed_at":null,"body":"**TypeScript Version:**  2.2.0-dev.20161112\r\n\r\n**Code**\r\n\r\n```ts\r\ntype Method = 'get' | 'post';\r\ntype Method2 = ('get' & string) | ('post' & string)\r\n\r\nlet app = {\r\n    get() { },\r\n    post() { }\r\n};\r\n\r\nlet methodA: Method = 'get';\r\nlet methodB: Method2 = 'get';\r\n\r\nlet handlerA = app[methodA]; // () => void\r\nlet handlerB = app[methodB]; // Error: Element implicitly has an any type because `{ get(): void, post(): void}` has no index signature\r\n```\r\n\r\n**Expected behavior:**\r\n`handlerA` and `handlerB` should have the same type inferred (because `Method` and `Method2` should be treated as the same type, by simplifying `Method2` down to `Method`).\r\n\r\n**Actual behavior:** \r\n`handlerA` is inferred correctly; `handlerB` errors/is implicitly any.\r\n\r\nFor context, here's the real code (and my attempt to fix it) that produced this problem: https://github.com/Microsoft/TypeScript/pull/12253#discussion_r88168082"},"comment":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/comments/261131258","html_url":"https://github.com/Microsoft/TypeScript/issues/12289#issuecomment-261131258","issue_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/12289","id":261131258,"user":{"login":"ethanresnick","id":471894,"avatar_url":"https://avatars.githubusercontent.com/u/471894?v=3","gravatar_id":"","url":"https://api.github.com/users/ethanresnick","html_url":"https://github.com/ethanresnick","followers_url":"https://api.github.com/users/ethanresnick/followers","following_url":"https://api.github.com/users/ethanresnick/following{/other_user}","gists_url":"https://api.github.com/users/ethanresnick/gists{/gist_id}","starred_url":"https://api.github.com/users/ethanresnick/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ethanresnick/subscriptions","organizations_url":"https://api.github.com/users/ethanresnick/orgs","repos_url":"https://api.github.com/users/ethanresnick/repos","events_url":"https://api.github.com/users/ethanresnick/events{/privacy}","received_events_url":"https://api.github.com/users/ethanresnick/received_events","type":"User","site_admin":false},"created_at":"2016-11-17T01:52:25Z","updated_at":"2016-11-17T01:52:25Z","body":"> keys<T>(obj: T): (keyof T)[];\r\n\r\nThe problem with that is it won't work for primitives (e.g. `keys(\"foo\")`), so I was distinguishing them from objects with the `T extends { [key: string]: any }`. Is there a better way to do that? (Regardless, that's kinda tangential.)\r\n\r\n> However, not that this approach for typing the of keys method is only correct when T represents the exact type of an object which often isn't the case.\r\n\r\nAhh. I hadn't thought about that, and it does seem like a big problem. Does that mean we should give up on using `keyof` for `Object.keys` and `Object.entries`? Or, is there a way to save the approach? In practice, it seems like it's pretty hard to create an object that has extra properties and yet doesn't have an index signature, right? So maybe this isn't a big deal?"}}
{"actor":{"display_login":"ethanresnick"}}