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')
}
}
playground
Expected behavior:
It should still work (because clearly in this case it can only return those values, or throw an error).
Actual behavior:
Error
TypeScript Version: 3.4.5
Search Terms:
Exhaustive switch return type does not work when wrapped in a try-catch
Code
playground
Expected behavior:
It should still work (because clearly in this case it can only return those values, or throw an error).
Actual behavior:
Error