Closed
Description
TypeScript Version: v3.1.3
Search Terms:
strictNullChecks, switch, case, condition, if, variable is used before being assigned.
Code
const enum Test {
A, B
}
function test(x: Test) {
let bork: string;
switch (x) {
case Test.A: {
bork = 'a';
break;
}
case Test.B: {
bork = 'b';
break;
}
}
return bork;
// ^^^^
// Variable 'bork' is used before being assigned.
}
Expected behavior:
No errors here.
TS should know about all possible checks. Right now we can get some kind of error: Not all code paths return a value.
in cases when we didn't define all possible case
s or when default
has been omited.
Actual behavior:
We got an error Variable is used before being assigned
. It also happens with if-else-if
variant.
Playground Link:
Click Me!
Related Issues:
Possible related issue: #27239. But this one is out of the loop.
Also: #9655, #10470, #17358, #20409, #23271.
Metadata
Metadata
Assignees
Labels
No labels