-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
[Feature Request] A way to instruct how to infer this
#15836
Comments
We actually shipped this in TypeScript 2.3 to support APIs like those in Ember and Vue. See #14141. |
For the record, you probably want extend<T, K>(cls: (...args: {}[]) => T, xtn: K & ThisType<T & K>): new (...args: {}[]) => T & K |
It looks awesome. But I couldn't make it work. Tried adding And makes me wonder if the following is doable interface Observable {
/**
* Very long long long comment to explain how to use `options`
*/
on(event: string, handler: Function, options?: object): Observable
}
interface MyClass extends Observable {
// ...
} We know that using Edit: My fault on some interface declaration. it works perfect. |
interface Observable {
/**
* Very long long long comment to explain how to use `options`
*/
on(event: string, handler: Function, options?: object): this
}
interface MyClass extends Observable {
// ...
} |
TypeScript Version: 2.3.2
Code
I have this definition:
Usage:
The
NewClass
will still have all expected methodinit
..., but thethis
cannot be inferred inside the extension object.It would be great if there is a way to instruct Typescript how to infer the
this
inside extension object based on the first passed param meter. (MyClass
in the example). The reason is to have better intellisense.The text was updated successfully, but these errors were encountered: