Skip to content

Infer "this" from extended classes #17513

@eliottrobson

Description

@eliottrobson

TypeScript Version: 2.4.0

Code

class B {
    static make() {
        return new this;
    }
}

class A extends B {
    id = 1;
}

console.log(typeof A.make().id);

Expected behavior:
A.make().id can be inferred to be the id (1)

Actual behavior:
A.make() is typehinted to return "B" where it returns "A" at runtime.

this inference

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