Skip to content

Give {} some other type than {} so it doesn't cause subtype reduction problems with primitives #37931

@xiaoxiangmoe

Description

@xiaoxiangmoe

TypeScript Version: 3.9.0-beta

Search Terms:
Array
Code

let a = [{a:1},1,2,3] // OK, Expected (number | { a: number; })[]
let b = [{},1,2,3] // Error,  Expected: `({}|1)[]` Actual: `{}[]`

Playground Link:

Playground Link

Related Issues:

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs ProposalThis issue needs a plan that clarifies the finer details of how it could be implemented.SuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions