-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Can't extend mixin constructor that constructs a generic type #13807
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
Comments
@mhegazy mentioned offline that |
Is there a real world scenario for this? Just trying to understand what you want to accomplish. We would obviously need to ensure |
@ahejlsberg, here's a real commit where I'm trying to combine mixins and generics: class Test<T> implements Interface<T> {}
class Demo<T> extends withMixin<T, Constructor<Interface<T>>>(Test) {} throws the error If I try specifying the argument |
(I've updated that diff to include the workaround from #14017 (comment). To see what I had before, click here.) |
Summary: This is the first operator to move into its own mixin (as scaffolded in http://codereview.cc/D2993). TypeScript doesn't seem to handle the types of mixed classes properly when used with generics: microsoft/TypeScript#13807 Related: #114 Reviewers: O2 Material Motion, O3 Material JavaScript platform reviewers, #material_motion, shyndman, featherless Reviewed By: O2 Material Motion, #material_motion, featherless Subscribers: featherless Tags: #material_motion Differential Revision: http://codereview.cc/D3000
Any resolution on this? I'm trying to do something similar where I want to use a class-mixin in another class-mixin. A small example here: class MyClass {
myClass = 1;
}
type Constructor<T extends MyClass> = new (...args: any[]) => T;
function make1<T extends Constructor<MyClass>>(base: T) {
return class extends base {
make1 = 1;
};
}
/**
* [ts] Type '{
* new (...args: any[]): make3<T>.(Anonymous class);
* prototype: make3<any>.(Anonymous class); } & T'
* is not a constructor function type. [2507]
*/
function make2<T extends Constructor<MyClass>>(base: T) {
return class extends make1(base) {
make2 = 2;
};
}
class Test extends MyClass {}
class Test2 extends make2(Test) {
constructor() {
super();
// this.myClass is gone
// this.make1 is gone
// only this.test2 exists
}
} |
Anything to say about this? Is there a workaround possible? I'm anxious to hear about this, since we need it. Another option could be that this is not proper coding, then I'd like to hear about it, as well. |
This applies regardless of whether or not I intersect it with some bogus type, or have a reasonable constraint. So none of the following works.
Returning a plain
T
Constructor of
T
with a bogus object type ({}
)Constructor of
T
whereT
is constrained to{}
Constructor of
T
whereT
is constrained toobject
(see also #13805)The text was updated successfully, but these errors were encountered: