-
Notifications
You must be signed in to change notification settings - Fork 13k
Open
Labels
Fix AvailableA PR has been opened for this issueA PR has been opened for this issuePossible ImprovementThe current behavior isn't wrong, but it's possible to see that it might be better in some casesThe current behavior isn't wrong, but it's possible to see that it might be better in some cases
Milestone
Description
π 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
π» 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
Metadata
Metadata
Assignees
Labels
Fix AvailableA PR has been opened for this issueA PR has been opened for this issuePossible ImprovementThe current behavior isn't wrong, but it's possible to see that it might be better in some casesThe current behavior isn't wrong, but it's possible to see that it might be better in some cases