Skip to content

Constrained nullable generics are not control flow checked #14415

Closed
@tinganho

Description

@tinganho
interface Banana {
    color: 'yellow';
}

class Monkey<T extends Banana | undefined> {
    a: T;

    render() {
        if (this.a) {
            this.a.color; // error Property 'color' does not exists on type 'T'
        }
    }
}

interface BigBanana extends Banana {
}

class BigMonkey extends Monkey<BigBanana> {
    render() {
        if (this.a) {
            this.a.color;
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions