Skip to content

instanceof should error when all constituents of a union are primitives #18519

@DanielRosenwasser

Description

@DanielRosenwasser
function foo(x: number | string) {
    if (x instanceof Number) {
        x
    }
}

Expected:

The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter

Actual:

No error, incorrect narrowing behavior (#14426)

Edit: Corrected the example to actually be a union.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptFixedA PR has been merged for this issueHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions