Skip to content

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

Closed

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

Activity

  1. DanielRosenwasser commented on Oct 4, 2015

    @DanielRosenwasser
    Member

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

  2. added
    BugA bug in TypeScript
    Effort: ModerateRequires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".
    and removed on Oct 4, 2015
  3. tinganho commented on Oct 5, 2015

    @tinganho
    ContributorAuthor
  4. weswigham commented on Nov 11, 2015

    @weswigham
    Member

    Fixed by #5442.

  5. locked and limited conversation to collaborators on Jun 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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