【发布时间】:2019-02-13 16:45:51
【问题描述】:
我正在尝试在 typescript 中实现 mixins,并从 mixin 类中获得自动完成功能。这是我的代码:
export type Constructor<T> = new (...args: any[]) => T;
export interface Test {
methodA();
methodB();
}
export type TestCtor = Constructor<Test>;
export function mixinTest<T extends Constructor<{}>>(base: T): TestCtor & T {
return class extends base {
constructor(...args: any[]) { super(...args); }
methodA() { }
methodB() {}
};
}
class A<T> {
value: T;
constructor(param: string) {}
}
class B extends mixinTest(A<{id: string}>) {
}
new B().methodA();
但我得到了错误:没有基本构造函数有数字 指定的参数
或使用泛型:
预期有 1 个参数,但得到了 3 个
我错过了什么?
【问题讨论】:
标签: typescript