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
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.
π Expected behavior
Expected there not to be an TS error.
The text was updated successfully, but these errors were encountered:
ide
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
Feb 12, 2022
Bug Report
The error described below started with TypeScript 4.6.1-rc. A minimal repro is included.
π Search Terms
π Version & Regression Information
β― Playground Link
Playground link with relevant code
π» Code
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. (Thedefault
clause is unnecessary if assuming TS is sound but one can see why a safety net is helpful.)π Actual behavior
The line
const [operator, ...operands] = expression;
produces the error:TS2488: Type 'never' must have a '[Symbol.iterator]()' method that returns an iterator.
π Expected behavior
Expected there not to be an TS error.
The text was updated successfully, but these errors were encountered: