Skip to content

Erroneous control flow type narrowing in loops #15835

Closed
@dead-claudia

Description

@dead-claudia

TypeScript Version: 2.3.2

Code

const enum Escape {None, Any}

function scan(): void {
    let escape: Escape = Escape.None;

    while (true) {
        // Error: Operator '===' cannot be applied to types 'Escape.None' and 'Escape.Any'.
        escape = escape === Escape.Any ? Escape.None : Escape.Any;
    }
}

Expected behavior:

The type to be correctly broadened, since it's in a loop.

Actual behavior:

The error denoted in the code comment above the line in question.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions