Skip to content

Behavior for conflicting type guards is inconsistent #4874

Closed
@DanielRosenwasser

Description

@DanielRosenwasser

The following causes an assignment error on x:

declare const stringOrNumber: string | number;

if (typeof stringOrNumber === "number")
    if (typeof stringOrNumber !== "number") {
        let x: number = stringOrNumber;
    }
}

whereas the following does not:

if (typeof stringOrNumber === "number" && typeof stringOrNumber !== "number") {
    let x: number = stringOrNumber
}

inconsistentconflictingtypeguards

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptFixedA PR has been merged for this issue

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions