Skip to content

Return type of an inherited static method returning "new this()" is incorrectly the base class, but it's the child class in runtime #11793

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
TomMarius opened this issue Oct 22, 2016 · 4 comments
Labels
Suggestion An idea for TypeScript Too Complex An issue which adding support for may be too complex for the value it adds

Comments

@TomMarius
Copy link

TypeScript Version: 2.0.3

Code

class A
{
    static X()
    {
        return new this();
    }
}

class B extends A
{
}

const shouldBeB = B.X();

Expected behavior:
The compiler correctly infers the type of shouldBeB as B.

Actual behavior:
The compiler infers the type of shouldBeB as A, but it's B in runtime.

@TomMarius TomMarius changed the title Return type of an inherited static method returning "new this()" is the base class, but it's the child class in runtime Return type of an inherited static method returning "new this()" is incorrectly the base class, but it's the child class in runtime Oct 22, 2016
@yortus
Copy link
Contributor

yortus commented Oct 22, 2016

Duplicate of #5863?

@TomMarius
Copy link
Author

TomMarius commented Oct 22, 2016

@yortus I feel like that's a feature suggestion, but I think it's a critical bug, so I made a separate issue.

@HerringtonDarkholme
Copy link
Contributor

You can always use #5863 (comment) for the same behavior

@RyanCavanaugh RyanCavanaugh added Suggestion An idea for TypeScript In Discussion Not yet reached consensus labels Oct 24, 2016
@RyanCavanaugh RyanCavanaugh added Too Complex An issue which adding support for may be too complex for the value it adds and removed In Discussion Not yet reached consensus labels Aug 12, 2017
@RyanCavanaugh
Copy link
Member

Too architecturally difficult to solve given the apparent lack of need for it

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Suggestion An idea for TypeScript Too Complex An issue which adding support for may be too complex for the value it adds
Projects
None yet
Development

No branches or pull requests

4 participants