Skip to content

Expressions in typeof undefined checks should not error on undefined #18940

Closed
@tinganho

Description

@tinganho

I think typeof undefined checks should not error in the last accessor of the expression. Because I'm already checking for undefined:

So below code should be perfectly fine:

interface A {
    a: string;
}

interface B {
    b: string;
}

function isA(x: A | B): x is A {
    return typeof x.a !== 'undefined'; // Error in "a" does not exists
}

Right now, I have to type assert x to any.

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