Closed
Description
TypeScript Version: [email protected]
Search Terms: switch
Code
const assertUnreachable = (x: never): void => {}
const f = (x: 'a' | 'b') => {
switch (x) {
case 'a':
{
}
break;
case 'a':
{
}
break;
}
};
const g = (x: { t1: 'a'; t2: 'a1' | 'a2' } | { t1: 'b'; t2: 'b1' | 'b2' }) => {
switch (x.t1) {
case 'a':
{
switch (x.t2) {
case 'a1':
{
}
break;
case 'a2':
{
}
break;
default: {
assertUnreachable(x.t2);
}
}
}
break;
}
};
Expected behavior:
Function f
should not pass the typecheck at the second case
block.
Function g
should pass the typecheck at assertUnreachable
.
Actual behavior:
Function f
passes the typecheck at the second case
block.
Function g
doesn't pass the typecheck at assertUnreachable
.
Note that if we put assertUnreachable
in function f
, it will work. So this seems to be only happening for the nested switch.