Closed
Description
TypeScript Version: 2.0.0-beta
Code
function fail(): never {
throw 'error';
}
enum E {
A,
B
}
function f(t: E) {
let s: string;
switch (t) {
case E.A:
s = 'a';
break;
case E.B:
s = 'b';
break;
default:
fail(); // but replacing with "throw 'error"' removes the TS error.
}
s += '';
}
Expected behavior:
s += '' is allowed because all terminating (non-throwing) branches assign to s.
In general, I am working under the assumption that calling functions that returning never are equivalent to raw throw calls during control-flow analysis.
Actual behavior:
ERROR(21,3): : Variable 's' is used before being assigned.