microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
101.02k stars 12.49k forks source link

Supporting type `self` or something that can represents the current instance. #2179

Closed vilicvane closed 9 years ago

vilicvane commented 9 years ago

When I am writing a declaration file, I found it really frustrating repeating the inherited method that returns the instance itself for a correct return type.

E.g. for animation library GSAP, many classes are inherited from class Animation, I have to repeat almost every method to update return type Animation to the current class.

class Animation {
    chain(): Animation;
}

class TweenLite extends Animation {
    ownProperty: any;
    chain(): TweenLite;
}

It would be great if we may use some type like self to make this easier, like this:

class Animation {
    chain(): self;
}

class TweenLite extends Animation {
    ownProperty: any;
}
DanielRosenwasser commented 9 years ago

Seems like a duplicate of #285.

danquirk commented 9 years ago

Also see #513