Skip to content

Type narrowing strategy for most closest type selection #6589

Closed
@falsandtru

Description

@falsandtru
class A<T> {
    private x: number;
    public m(p: T): T {
        return p;
    }
}
class B extends A<string> {
    private y: number;
}
var a: A<number> | B;
if (a instanceof B) {
    a.m(''); // `a` is `B`
}
if (a instanceof A) {
    a.m(1); // `a` is `A<number> | B`, should be `A<number>`
}

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