π Search Terms
TS2488
π Version & Regression Information
- This changed between versions 3.8.3 and 3.9.7 (tested with the playground)
- I was unable to test this with every-ts because this issue seems to affect only the editor, not
tsc
β― Playground Link
https://www.typescriptlang.org/play/?ts=3.9.7#code/CYUwxgNghgTiAEA3W8AeAueA7ArgWwCMQYBtAXXgB94BveAF0wHIon4BfeAMloeYLbsAUBBD14JEKLwUAvGiA
π» Code
declare var x: number[] | { t: 'a' } & { t: 'b' }
let [elem] = x
π Actual behavior
The array destructure fails with this error:
Type 'number[]' must have a '[Symbol.iterator]()' method that returns an iterator.(2488)
π Expected behavior
No error should be present.
Since an object cannot have a field t that holds both 'a' and 'b', { t: 'a' } & { t: 'b' } reduces to never. And number[] | never decays to number[], which is iterable by definition.
Additional information about the issue
No response
π Search Terms
TS2488
π Version & Regression Information
tscβ― Playground Link
https://www.typescriptlang.org/play/?ts=3.9.7#code/CYUwxgNghgTiAEA3W8AeAueA7ArgWwCMQYBtAXXgB94BveAF0wHIon4BfeAMloeYLbsAUBBD14JEKLwUAvGiA
π» Code
π Actual behavior
The array destructure fails with this error:
π Expected behavior
No error should be present.
Since an object cannot have a field
tthat holds both'a'and'b',{ t: 'a' } & { t: 'b' }reduces tonever. Andnumber[] | neverdecays tonumber[], which is iterable by definition.Additional information about the issue
No response