-
Notifications
You must be signed in to change notification settings - Fork 13k
Open
Labels
BugA bug in TypeScriptA bug in TypeScript
Milestone
Description
TypeScript Version: master
Search Terms: unreachable throw return narrowing
Code
function fn() {
// TODO: Finish writing this function!
return;
const h = Math.random() > 0.5 ? 'h' : undefined;
if (h) {
// Error, wat
const a: string = h;
}
}
Expected behavior: No error
Actual behavior: Error - h is possibly undefined
We get "bug" reports like this every once in a while, and it's hard to understand why the narrowing just stops working because the code isn't reachable. This also makes it difficult to insert debugging throws/returns earlier in the function.
e.g. https://twitter.com/aendrew/status/1037301561062514688
Related Issues: Believe there's one out there somewhere
aendra-rininsland, WiseBird, cpplearner, hraban, atg and 21 moreaendra-rininsland and conoremclaughlin
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScript