-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issue
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.
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issue