Skip to content

Narrowed type of variable isn't obtained by aliases of the variable #26372

Closed
@sandersn

Description

@sandersn
function f() {}
f.p = { x: "" };
const p = f.p;
if (1 + 1 < 2) {
    f.p = { x: 0 };
}
f.p.x = 0;
p.x.toUpperCase(); // No compile error, crash at runtime

Expected behavior:

Error on p.x.toUpperCase()

Actual behavior:
No error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Design LimitationConstraints of the existing architecture prevent this from being fixed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions