typescript - 扩展抽象类的类型类
问题描述
我有几个用静态方法扩展抽象类的类:
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)
如果可能有帮助,我正在使用续集。
解决方案
推荐阅读
- java - Spring Boot 最新版本中 jdbctemplate 的 @autowired 问题
- reactjs - 在单元测试中的 React Native renderer.create() 调用中 Ref 为空,这未通过我的测试
- haskell - 为什么这种类型注释是错误的?
- ios - 根据当前语言更改文本字段的视图模式
- reactjs - 如何知道另一个子组件中一个子组件的事件
- asp.net - 如何将 URL 路径映射到 asp.net 网站中的物理路径
- javascript - 平铺地图未在 HTML5 中呈现
- javascript - 我想使用 javascript 和表单发送多个值
- python - 在 DataFrame 中插入系列
- excel - Excel中的多个嵌套IF语句