Skip to content

Type guards doesn't work on multilevel if statements #5100

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
tinganho opened this issue Oct 4, 2015 · 3 comments
Closed

Type guards doesn't work on multilevel if statements #5100

tinganho opened this issue Oct 4, 2015 · 3 comments
Labels
Bug A bug in TypeScript Effort: Moderate Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual". Fixed A PR has been merged for this issue

Comments

@tinganho
Copy link
Contributor

tinganho commented Oct 4, 2015

I just noticed that type guards doesn't work on multilievel if statements? Is it by design?

var t: string | boolean | number;
if (typeof t === 'boolean' || typeof t === 'number') {
    if (typeof t === 'number') {        
    }
    else {
        t // should be boolean, but is string | boolean
    }
}
@DanielRosenwasser
Copy link
Member

I wonder if this is at all related to #4874, but it definitely seems like a bug.

@DanielRosenwasser DanielRosenwasser added Bug A bug in TypeScript Help Wanted You can do this Effort: Moderate Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual". and removed Help Wanted You can do this labels Oct 4, 2015
@tinganho
Copy link
Contributor Author

tinganho commented Oct 5, 2015

@DanielRosenwasser I think it is related.

@weswigham
Copy link
Member

Fixed by #5442.

@RyanCavanaugh RyanCavanaugh added Fixed A PR has been merged for this issue and removed Help Wanted You can do this labels 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 Effort: Moderate Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual". Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

6 participants