Skip to content

Spreading an extra {}[] to an array results in bad inferenceΒ #62347

@devanshj

Description

@devanshj

πŸ”Ž Search Terms

Spreading arrays, weak type unions

πŸ•— Version & Regression Information

Tested with v5.9.2

⏯ Playground Link

https://www.typescriptlang.org/play/?#code/CYUwxgNghgTiAEEQBd5QFzwN7wGYHt8B+TAVwDsBrc-Ad3PgF8BtAXQChRJYElUAjTFhYc+8AB5C8hEvADOyGAEtyAcyZt4AXnjMAdAait48APSn4wfCDnkA5KjD4AtgAclSADTxVhYOzEATykCYkwFZTUNYx19Q28DPX5jc3gnNw8bb34oYCA

πŸ’» Code

declare let a: { foo?: unknown }[]
declare let b: {}[]
let x: { foo?: string }[] = [...a]  // doesn't compile, good
let y: { foo?: string }[] = [...a, ...b] // compiles, bad

πŸ™ Actual behavior

The declaration y type-checks

πŸ™‚ Expected behavior

The declaration y should not type-check.

Additional information about the issue

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Not a DefectThis behavior is one of several equally-correct options

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions