{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/9842","repository_url":"https://api.github.com/repos/Microsoft/TypeScript","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/9842/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/9842/comments","events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/9842/events","html_url":"https://github.com/Microsoft/TypeScript/issues/9842","id":166630630,"number":9842,"title":"Narrowing union types with array's indexOf","user":{"login":"wallverb","id":1723815,"avatar_url":"https://avatars.githubusercontent.com/u/1723815?v=3","gravatar_id":"","url":"https://api.github.com/users/wallverb","html_url":"https://github.com/wallverb","followers_url":"https://api.github.com/users/wallverb/followers","following_url":"https://api.github.com/users/wallverb/following{/other_user}","gists_url":"https://api.github.com/users/wallverb/gists{/gist_id}","starred_url":"https://api.github.com/users/wallverb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wallverb/subscriptions","organizations_url":"https://api.github.com/users/wallverb/orgs","repos_url":"https://api.github.com/users/wallverb/repos","events_url":"https://api.github.com/users/wallverb/events{/privacy}","received_events_url":"https://api.github.com/users/wallverb/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-07-20T16:56:25Z","updated_at":"2016-07-20T19:34:37Z","closed_at":null,"body":"It would be great if TS could handle this:\r\n\r\n```ts\r\n                if (typeof reply == 'string') {\r\n\r\n                }\r\n                else if (~['input', 'button'].indexOf(reply.typeName)) {\r\n                    const test = reply // Input or Button - currently everything\r\n                }\r\n```"},"comment":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/comments/234057379","html_url":"https://github.com/Microsoft/TypeScript/issues/9842#issuecomment-234057379","issue_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/9842","id":234057379,"user":{"login":"DanielRosenwasser","id":972891,"avatar_url":"https://avatars.githubusercontent.com/u/972891?v=3","gravatar_id":"","url":"https://api.github.com/users/DanielRosenwasser","html_url":"https://github.com/DanielRosenwasser","followers_url":"https://api.github.com/users/DanielRosenwasser/followers","following_url":"https://api.github.com/users/DanielRosenwasser/following{/other_user}","gists_url":"https://api.github.com/users/DanielRosenwasser/gists{/gist_id}","starred_url":"https://api.github.com/users/DanielRosenwasser/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DanielRosenwasser/subscriptions","organizations_url":"https://api.github.com/users/DanielRosenwasser/orgs","repos_url":"https://api.github.com/users/DanielRosenwasser/repos","events_url":"https://api.github.com/users/DanielRosenwasser/events{/privacy}","received_events_url":"https://api.github.com/users/DanielRosenwasser/received_events","type":"User","site_admin":false},"created_at":"2016-07-20T19:34:37Z","updated_at":"2016-07-20T19:34:37Z","body":"There's a lot going on there that would need to be formalized. Specifically:\r\n\r\n1. The expression of a property access becomes a literal type location.\r\n2. An array literal becomes a literal type location if its parent is a literal type location.\r\n3. `indexOf` would need to have a way of expressing that any value `>=` 0 implies that its type is related to its array's numeric index signature.\r\n\r\n(1) and (2) are very easy to implement, but I think that (3) is too complex to express right now. While we have type predicate functions, we'd need a more powerful mechanism for expressing relationships between produced values and their arguments."}}
{"actor":{"display_login":"DanielRosenwasser"}}