You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
TypeScript 4.6 sometimes treats tuple union types as "never" when switch-case has a "default" clauseΒ #47857
See this toy NAND evaluator. Something about the recursive union type causes TS to fail when destructuring the array. Deleting the default clause causes the error to go away. (The default clause is unnecessary if assuming TS is sound but one can see why a safety net is helpful.)
exporttypeExpression=BooleanLogicExpression|'true'|'false';exporttypeBooleanLogicExpression=['and', ...Expression[]]|['not',Expression];exportfunctionevaluate(expression: Expression): boolean{if(Array.isArray(expression)){const[operator, ...operands]=expression;switch(operator){case'and': {returnoperands.every((child)=>evaluate(child));}case'not': {return!evaluate(operands[0]);}default: {thrownewError(`${operator} is not a supported operator`);}}}else{returnexpression==='true';}}
π Actual behavior
The line const [operator, ...operands] = expression; produces the error: TS2488: Type 'never' must have a '[Symbol.iterator]()' method that returns an iterator.
changed the title [-]TypeScript 4.6 sometimes treats tuple union types as "never"[/-][+]TypeScript 4.6 sometimes treats tuple union types as "never" when switch-case has a "default" clause[/+]on Feb 12, 2022
Activity
[-]TypeScript 4.6 sometimes treats tuple union types as "never"[/-][+]TypeScript 4.6 sometimes treats tuple union types as "never" when switch-case has a "default" clause[/+]gabritto commentedon Feb 15, 2022
Bisected to 56f8107
gabritto commentedon Feb 16, 2022
After some more digging, the error arises in new code added by #46266.