{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/24723","repository_url":"https://api.github.com/repos/Microsoft/TypeScript","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/24723/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/24723/comments","events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/24723/events","html_url":"https://github.com/Microsoft/TypeScript/issues/24723","id":329834919,"node_id":"MDU6SXNzdWUzMjk4MzQ5MTk=","number":24723,"title":"Throwing Error from separate function","user":{"login":"KhramtsovMaksim","id":11661729,"node_id":"MDQ6VXNlcjExNjYxNzI5","avatar_url":"https://avatars0.githubusercontent.com/u/11661729?v=4","gravatar_id":"","url":"https://api.github.com/users/KhramtsovMaksim","html_url":"https://github.com/KhramtsovMaksim","followers_url":"https://api.github.com/users/KhramtsovMaksim/followers","following_url":"https://api.github.com/users/KhramtsovMaksim/following{/other_user}","gists_url":"https://api.github.com/users/KhramtsovMaksim/gists{/gist_id}","starred_url":"https://api.github.com/users/KhramtsovMaksim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/KhramtsovMaksim/subscriptions","organizations_url":"https://api.github.com/users/KhramtsovMaksim/orgs","repos_url":"https://api.github.com/users/KhramtsovMaksim/repos","events_url":"https://api.github.com/users/KhramtsovMaksim/events{/privacy}","received_events_url":"https://api.github.com/users/KhramtsovMaksim/received_events","type":"User","site_admin":false},"labels":[{"id":113971226,"node_id":"MDU6TGFiZWwxMTM5NzEyMjY=","url":"https://api.github.com/repos/Microsoft/TypeScript/labels/Duplicate","name":"Duplicate","color":"f7c6c7","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-06-06T11:53:08Z","updated_at":"2018-06-14T13:19:04Z","closed_at":null,"author_association":"NONE","body":"**TypeScript Version:**  2.9.1\r\n\r\n**Search Terms:** throw, Error, callback\r\n\r\n**Code**\r\n\r\n```ts\r\n// --strict\r\nfunction onError(error: Error): never {\r\n\tthrow error;\r\n}\r\n\r\nconst numbers: number[] = [1, 2, 3];\r\n\r\nfunction getAllowedNumberOrThrow1(n: number): number | never {\r\n\tconst nFromArray = numbers.find(num => num === n);\r\n\r\n\tif (nFromArray === undefined) {\r\n\t\tonError(new Error(`There is no ${n} in [${numbers.join(\", \")}]`));\r\n\t}\r\n\r\n\t/*\r\n\tType 'number | undefined' is not assignable to type 'number'.\r\n\tType 'undefined' is not assignable to type 'number'.\r\n\t*/\r\n\treturn nFromArray;\r\n}\r\n\r\n\r\nfunction getAllowedNumberOrThrow2(n: number): number | never {\r\n\tconst nFromArray = numbers.find(num => num === n);\r\n\r\n\tif (nFromArray === undefined) {\r\n\t\tthrow new Error(`There is no ${n} in [${numbers.join(\", \")}]`);\r\n\t}\r\n\r\n\t// OK\r\n\treturn nFromArray;\r\n}\r\n```\r\nIf the error throwing is encapsulated in a separate function on the program (`onError`), the compiler does not understand that the execution thread is terminated at the place of calling this function `onError` in `--strict` mode\r\n\r\n**Expected behavior:** compiler do type check right way\r\n\r\n**Actual behavior:** compiler ignore result of `onError`\r\n\r\n**Playground Link:** http://www.typescriptlang.org/play/index.html#src=function%20onError(error%3A%20Error)%3A%20never%20%7B%0D%0A%09throw%20error%3B%0D%0A%7D%0D%0A%0D%0Aconst%20numbers%3A%20number%5B%5D%20%3D%20%5B1%2C%202%2C%203%5D%3B%0D%0A%0D%0Afunction%20getAllowedNumberOrThrow1(n%3A%20number)%3A%20number%20%7C%20never%20%7B%0D%0A%09const%20nFromArray%20%3D%20numbers.find(num%20%3D%3E%20num%20%3D%3D%3D%20n)%3B%0D%0A%0D%0A%09if%20(nFromArray%20%3D%3D%3D%20undefined)%20%7B%0D%0A%09%09onError(new%20Error(%60There%20is%20no%20%24%7Bn%7D%20in%20%5B%24%7Bnumbers.join(%22%2C%20%22)%7D%5D%60))%3B%0D%0A%09%7D%0D%0A%0D%0A%09%2F*%0D%0A%09Type%C2%A0'number%C2%A0%7C%C2%A0undefined'%C2%A0is%C2%A0not%C2%A0assignable%C2%A0to%C2%A0type%C2%A0'number'.%0D%0A%09Type%C2%A0'undefined'%C2%A0is%C2%A0not%C2%A0assignable%C2%A0to%C2%A0type%C2%A0'number'.%0D%0A%09*%2F%0D%0A%09return%20nFromArray%3B%0D%0A%7D%0D%0A%0D%0A%0D%0Afunction%20getAllowedNumberOrThrow2(n%3A%20number)%3A%20number%20%7C%20never%20%7B%0D%0A%09const%20nFromArray%20%3D%20numbers.find(num%20%3D%3E%20num%20%3D%3D%3D%20n)%3B%0D%0A%0D%0A%09if%20(nFromArray%20%3D%3D%3D%20undefined)%20%7B%0D%0A%09%09throw%20new%20Error(%60There%20is%20no%20%24%7Bn%7D%20in%20%5B%24%7Bnumbers.join(%22%2C%20%22)%7D%5D%60)%3B%0D%0A%09%7D%0D%0A%0D%0A%09%2F%2F%20OK%0D%0A%09return%20nFromArray%3B%0D%0A%7D\r\n"},"comment":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/comments/397293129","html_url":"https://github.com/Microsoft/TypeScript/issues/24723#issuecomment-397293129","issue_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/24723","id":397293129,"node_id":"MDEyOklzc3VlQ29tbWVudDM5NzI5MzEyOQ==","user":{"login":"KhramtsovMaksim","id":11661729,"node_id":"MDQ6VXNlcjExNjYxNzI5","avatar_url":"https://avatars0.githubusercontent.com/u/11661729?v=4","gravatar_id":"","url":"https://api.github.com/users/KhramtsovMaksim","html_url":"https://github.com/KhramtsovMaksim","followers_url":"https://api.github.com/users/KhramtsovMaksim/followers","following_url":"https://api.github.com/users/KhramtsovMaksim/following{/other_user}","gists_url":"https://api.github.com/users/KhramtsovMaksim/gists{/gist_id}","starred_url":"https://api.github.com/users/KhramtsovMaksim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/KhramtsovMaksim/subscriptions","organizations_url":"https://api.github.com/users/KhramtsovMaksim/orgs","repos_url":"https://api.github.com/users/KhramtsovMaksim/repos","events_url":"https://api.github.com/users/KhramtsovMaksim/events{/privacy}","received_events_url":"https://api.github.com/users/KhramtsovMaksim/received_events","type":"User","site_admin":false},"created_at":"2018-06-14T13:19:04Z","updated_at":"2018-06-14T13:19:04Z","author_association":"NONE","body":"@jack-williams, thank you. Work for me, but looks not well)"}}
{"actor":{"display_login":"KhramtsovMaksim"}}