【发布时间】:2019-01-30 22:02:14
【问题描述】:
这就是我想做的:
abstract class AbBase
static newDerived<T extends typeof AbBase>(this: T) {
return class A extends this {
//...
}
}
基本上我希望 newDerived 仅从非抽象实现中调用。
但是,我在 extends this 部分收到此错误:
“类型 'T' 不是构造函数类型。您的意思是让 T 被限制为类型 'new (...args: any[]) => AbBase'?”
但是如果我这样做了
static newDerived<T extends typeof AbBase>(this: new (...args: any[]) => AbstractInstanceType<T>) {
它说,“基本构造函数返回类型'AbstractInstanceType'不是对象类型或对象类型与静态已知成员的交集。”
【问题讨论】:
标签: typescript