首页 > 解决方案 > 扩展抽象类的类型类

问题描述

我有几个用静态方法扩展抽象类的类:

abstract class Model {
   {...}
   public static findAll() { ... }
}

class ModelA extends Model { ... }
...
class ModelZ extends Model { ... }

现在,我想编写一个函数,它接受一个扩展我的抽象类的类作为参数

function myFunction(model: typeof Model) {
...
model.findAll();
...
}

但我收到以下错误:Cannot assign an abstract constructor type to a non-abstract constructor type.ts(2684)

在此处输入图像描述

我怎样才能做到这一点 ?我不想写model: typeof ModelA | ... | typeof ModelZ

我也试过:

function myFunction<M extends typeof Model>(model: M)

在此处输入图像描述

如果可能有帮助,我正在使用续集。

标签: typescript

解决方案


推荐阅读