Skip to content

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

Closed
@tinganho

Description

@tinganho

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
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptEffort: ModerateRequires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".FixedA PR has been merged for this issue

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions