-
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
No autocompletions for Parent class when using ES2015 mixins (function returning the Class) #18732
Comments
There may be a better way to do this, but the main problem is that Base is of type type Constructable = new (...args) => any;
class Parent {
parentMethod() { }
}
const Mixin = <T extends Constructable>(Base: T) => class Mixin extends Base {
mixinMethod() { }
}
class Child extends Mixin(Parent) {
childMethod() {
this. // all three show up here in playground
}
} |
Nice! I tried to implement this using jsdoc syntax, but without luck, any ideas? /** @typedef {new (...args) => any} Constructable */
class Parent {
parentMethod() { }
}
/**
* @template T extends Constructable
* @param {T} Base
*/
const Mixin = (Base) => class Mixin extends Base {
mixinMethod() { }
}
class Child extends Mixin(Parent) {
childMethod() {
this. // still only two autocompletions
}
} |
I think the problem here is that TypeScript doesn't have a way of expressing constraints on type parameters in JSDoc. In other words: /**
* @template T extends Constructable
*/ doesn't actually add a constraint. @dimvar I see that you mentioned some work on bounded generics here for Closure. Any word on that? |
No progress on that yet. |
Is there anywhere that "types I can describe in TS but not JSDoc" (such as this) are listed? |
Hi! Did you achieve some progress on that field (I mean allowing constraints in the JSDoc In many scenarios, the previous approach (https://www.typescriptlang.org/docs/handbook/mixins.html) is not an option as it requires a massive code duplication (e.g. creating 15 fake properties and methods to satisfy interfaces). |
And I'd change the misleading title of the issue. When using |
OP works in latest on Playground |
@RyanCavanaugh |
Consider this code:
For the Child class, all three method are available, but typescript doesn't detect the
parentMethod
to be available.The text was updated successfully, but these errors were encountered: