Skip to content
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

Add keyword for the typed constructor of this #7418

Closed
trkjgrdg opened this issue Mar 7, 2016 · 2 comments
Closed

Add keyword for the typed constructor of this #7418

trkjgrdg opened this issue Mar 7, 2016 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@trkjgrdg
Copy link

trkjgrdg commented Mar 7, 2016

Consider the following classes:

class Animal {
    static verb = "moved";
    move() { alert("Animal " + Animal.verb); }
}

class Snake extends Animal {
    static verb = "slithered"; 
}

(new Snake()).move();

The above prints "Animal moved" because we hardcoded Animal.name in move. To make subclasses work properly, we should instead define move as:

move() { alert("Animal " + (<typeof Animal>this.constructor).verb); }

But using (<typeof Animal>this.constructor).verb everywhere is very verbose. It would be nice if there were a keyword (e.g. reuse class) that stood for <typeof Animal>this.constructor, so we could write just class.verb.

@trkjgrdg trkjgrdg changed the title Add keyword for the (typed) constructor of this Add keyword for the typed constructor of this Mar 7, 2016
@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Mar 7, 2016
@RyanCavanaugh
Copy link
Member

See #3841/ #4356.

@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
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

2 participants