-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Mixin classes don't allow constructors of _generic_ 'object' types #16390
Comments
I've also run into this. This is my workaround which allows a constraint on the base class ( type Constructor<T> = new (...args: any[]) => T;
interface IBase {
foo: number;
}
const Timestamped = <C extends Constructor<IBase>>(Base: C) =>
<T extends IBase>() =>
class extends Base {
timestamp = new Date;
};
class Base implements IBase {
foo = 5;
}
class Sub extends Timestamped(Base)<Base>() {
bar = 'ok';
}
let s = new Sub;
console.log(s.foo, s.bar, s.timestamp); I've haven't been able to find a way to avoid the double function call. |
I wonder if it possible to return generic class from mixin, like this: type Constructor<T> = new (...args: any[]) => T;
const List = <T extends Constructor<{}>>(Base: T) => class <T> extends Base {
values: T[];
constructor(...args: any[]) {
super(...args);
}
add(value: T) {
this.values.push(value);
}
};
class Item {
render() { }
}
class ItemList extends List(Item)<Item> {
render() {
this.values.forEach((item) => {
item.render();
});
}
}
const list = new ItemList();
console.log(list.values);
list.render(); For now it's produces error: |
lets fix the problem "is not a class or interface type" Basic requirement
@athasach
@zamb3zi
@evg656e
|
@lupuscaoticus Hi, I'm trying to give the type of a mixin, like this type Mixin = <S extends ClassType, I extends InstanceType<S>, M extends I> (B: S) => ClassType<M> However tsc says |
FWIW this looks like a duplicate of #13807 |
TypeScript Version: 2.3.4, 2.4.0-dev.20170609
Code:
Expected behavior:
Should be able to use the generic
I
as an argument toConstructor
.Actual behavior:
Compiling this yields the following error:
Note:
This is a variation on #13805 where the following compiles successfully:
The text was updated successfully, but these errors were encountered: