-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Labels
Experience EnhancementNoncontroversial enhancementsNoncontroversial enhancementsFixedA PR has been merged for this issueA PR has been merged for this issueSuggestionAn idea for TypeScriptAn idea for TypeScript
Milestone
Description
TypeScript Version: 3.4.5
Search Terms:
Exhaustive switch return type does not work when wrapped in a try-catch
Code
enum Foo {
One,
Two,
Three
}
function test(type: Foo): number {
switch (type) {
case Foo.One:
return 0;
case Foo.Two:
return 0;
case Foo.Three:
return 0;
}
}
function test2(type: Foo): number { // ERROR
try {
switch (type) {
case Foo.One:
return 0;
case Foo.Two:
return 0;
case Foo.Three:
return 0;
}
} catch (e) {
throw new Error('some error')
}
}Expected behavior:
It should still work (because clearly in this case it can only return those values, or throw an error).
Actual behavior:
Error
Metadata
Metadata
Assignees
Labels
Experience EnhancementNoncontroversial enhancementsNoncontroversial enhancementsFixedA PR has been merged for this issueA PR has been merged for this issueSuggestionAn idea for TypeScriptAn idea for TypeScript