{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/2388","repository_url":"https://api.github.com/repos/Microsoft/TypeScript","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/2388/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/2388/comments","events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/2388/events","html_url":"https://github.com/Microsoft/TypeScript/issues/2388","id":62340242,"number":2388,"title":"Use control flow analysis for type guards","user":{"login":"jedmao","id":1058243,"avatar_url":"https://avatars.githubusercontent.com/u/1058243?v=3","gravatar_id":"","url":"https://api.github.com/users/jedmao","html_url":"https://github.com/jedmao","followers_url":"https://api.github.com/users/jedmao/followers","following_url":"https://api.github.com/users/jedmao/following{/other_user}","gists_url":"https://api.github.com/users/jedmao/gists{/gist_id}","starred_url":"https://api.github.com/users/jedmao/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jedmao/subscriptions","organizations_url":"https://api.github.com/users/jedmao/orgs","repos_url":"https://api.github.com/users/jedmao/repos","events_url":"https://api.github.com/users/jedmao/events{/privacy}","received_events_url":"https://api.github.com/users/jedmao/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Microsoft/TypeScript/labels/Committed","name":"Committed","color":"009800"},{"url":"https://api.github.com/repos/Microsoft/TypeScript/labels/Suggestion","name":"Suggestion","color":"006b75"}],"state":"open","locked":false,"assignee":{"login":"ahejlsberg","id":4226954,"avatar_url":"https://avatars.githubusercontent.com/u/4226954?v=3","gravatar_id":"","url":"https://api.github.com/users/ahejlsberg","html_url":"https://github.com/ahejlsberg","followers_url":"https://api.github.com/users/ahejlsberg/followers","following_url":"https://api.github.com/users/ahejlsberg/following{/other_user}","gists_url":"https://api.github.com/users/ahejlsberg/gists{/gist_id}","starred_url":"https://api.github.com/users/ahejlsberg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ahejlsberg/subscriptions","organizations_url":"https://api.github.com/users/ahejlsberg/orgs","repos_url":"https://api.github.com/users/ahejlsberg/repos","events_url":"https://api.github.com/users/ahejlsberg/events{/privacy}","received_events_url":"https://api.github.com/users/ahejlsberg/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/Microsoft/TypeScript/milestones/1","html_url":"https://github.com/Microsoft/TypeScript/milestones/TypeScript%202.0","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/milestones/1/labels","id":721040,"number":1,"title":"TypeScript 2.0","description":"The next major release of TypeScript","creator":{"login":"RyanCavanaugh","id":6685088,"avatar_url":"https://avatars.githubusercontent.com/u/6685088?v=3","gravatar_id":"","url":"https://api.github.com/users/RyanCavanaugh","html_url":"https://github.com/RyanCavanaugh","followers_url":"https://api.github.com/users/RyanCavanaugh/followers","following_url":"https://api.github.com/users/RyanCavanaugh/following{/other_user}","gists_url":"https://api.github.com/users/RyanCavanaugh/gists{/gist_id}","starred_url":"https://api.github.com/users/RyanCavanaugh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RyanCavanaugh/subscriptions","organizations_url":"https://api.github.com/users/RyanCavanaugh/orgs","repos_url":"https://api.github.com/users/RyanCavanaugh/repos","events_url":"https://api.github.com/users/RyanCavanaugh/events{/privacy}","received_events_url":"https://api.github.com/users/RyanCavanaugh/received_events","type":"User","site_admin":false},"open_issues":129,"closed_issues":115,"state":"open","created_at":"2014-07-14T23:24:03Z","updated_at":"2016-03-22T20:47:05Z","due_on":null,"closed_at":null},"comments":15,"created_at":"2015-03-17T09:21:03Z","updated_at":"2016-03-23T07:45:20Z","closed_at":null,"body":"**TS 1.4**\r\n\r\nType guard fails to narrow the union type when returning early.\r\n\r\n```ts\r\nfunction foo(x: number | string) {\r\n\tif (typeof x === 'string') {\r\n\t\treturn;\r\n\t}\r\n\t// x should now be a number\r\n\tif (2 % x !== 0) {\r\n\t\t// do something\r\n\t}\r\n}\r\n```\r\n\r\nUnfortunately, I get the following compiler error:\r\n> The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.\r\n\r\nClearly, the compiler should know at this point that it can't possibly be dealing with a `string`, as that scenario has already been returned."},"comment":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/comments/200232537","html_url":"https://github.com/Microsoft/TypeScript/issues/2388#issuecomment-200232537","issue_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/2388","id":200232537,"user":{"login":"JsonFreeman","id":8052525,"avatar_url":"https://avatars.githubusercontent.com/u/8052525?v=3","gravatar_id":"","url":"https://api.github.com/users/JsonFreeman","html_url":"https://github.com/JsonFreeman","followers_url":"https://api.github.com/users/JsonFreeman/followers","following_url":"https://api.github.com/users/JsonFreeman/following{/other_user}","gists_url":"https://api.github.com/users/JsonFreeman/gists{/gist_id}","starred_url":"https://api.github.com/users/JsonFreeman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JsonFreeman/subscriptions","organizations_url":"https://api.github.com/users/JsonFreeman/orgs","repos_url":"https://api.github.com/users/JsonFreeman/repos","events_url":"https://api.github.com/users/JsonFreeman/events{/privacy}","received_events_url":"https://api.github.com/users/JsonFreeman/received_events","type":"User","site_admin":false},"created_at":"2016-03-23T07:45:20Z","updated_at":"2016-03-23T07:45:20Z","body":"@Arnavion I think in order to get the `filter` behavior, you would have to change the signature of `Array.filter` to have a type parameter `<U extends T>`. Additionally, this case would be blocked on #241."}}