Skip to content

Behavior for conflicting type guards is inconsistent #4874

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
DanielRosenwasser opened this issue Sep 19, 2015 · 1 comment
Closed

Behavior for conflicting type guards is inconsistent #4874

DanielRosenwasser opened this issue Sep 19, 2015 · 1 comment
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@DanielRosenwasser
Copy link
Member

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

@weswigham
Copy link
Member

Fixed by #5442.

@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Nov 11, 2015
@mhegazy mhegazy assigned weswigham and unassigned sandersn Nov 11, 2015
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

5 participants