Skip to content

Type guard variables do not get narrowed within class bodies #5619

Closed
@weswigham

Description

@weswigham

For example:

let x: string | number;

if (typeof x === "string") {

    let n = class {
        constructor() {
            x; // Should be "string" but is "string | number".
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptFixedA PR has been merged for this issue

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions