Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Bizarre type guard issue in 2.0 #10378

Copy link
Copy link
@jeffreymorlan

Description

@jeffreymorlan
Issue body actions
var a: boolean | number | string;
if (typeof a !== 'boolean') {
    // a is narrowed to "number | string"
    for (var i = 0; i < 1; i++) {
        for (var j = 0; j < 1; j++) {}
        if (typeof a === 'string') {
            // a is narrowed to "string'
            for (var j = 0; j < 1; j++) {
                a.length; // Error: Property 'length' does not exist on type 'never'.
            }
        }
    }
}

Removing any of the three loops, or the outer type guard, makes the problem disappear.

Reactions are currently unavailable

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issue

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.