Thanks to visit codestin.com
Credit goes to github.com

Skip to content

T[] | { t: 'a' } & { t: 'b' } is not iterable (TS2488)Β #62462

@satgo1546

Description

@satgo1546

πŸ”Ž 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Fix AvailableA 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 cases

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions