TypeScript Version: typescript@3.3.0-dev.20190124
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.
TypeScript Version: typescript@3.3.0-dev.20190124
Search Terms: switch
Code
Expected behavior:
Function
fshould not pass the typecheck at the secondcaseblock.Function
gshould pass the typecheck atassertUnreachable.Actual behavior:
Function
fpasses the typecheck at the secondcaseblock.Function
gdoesn't pass the typecheck atassertUnreachable.Note that if we put
assertUnreachablein functionf, it will work. So this seems to be only happening for the nested switch.