Closed
Description
TypeScript Version: 3.7.x-dev.201xxxxx
Search Terms:
- Mixin composition
- Recursive mixin
Code
type Constructor<T = any, A extends any[] = any[]> = new (...a: A) => T;
function CallbackInvokable<T extends Constructor>(base: T) {
return class extends base {
protected invoke(...args: any[]) { }
};
}
function EventTargeted<T extends Constructor>(base: T) {
// A event target should be callback-invoke-able.
// Error: Type "{ new (...a: any[]): CallbackInvokable<T>.(Anonymous class); prototype: CallbackInvokable<any>.(Anonymous class); } & T" is not a constructor type.
return class extends CallbackInvokable(base) {
public emit (...args: any[]) {
this.invoke(...args); // "invoke" doesn't exist on type (Anonymous Class).
}
};
}
class Empty {};
class Test extends CallbackInvokable(Empty) {}; // OK
class Resource extends EventTargeted(Empty) {}; // OK
Expected behavior:
No error reported.
Actual behavior:
Error reported, as commented above.
Playground Link:
Related Issues: