【发布时间】:2019-01-13 00:05:42
【问题描述】:
我创建了一个 Tools 类来扩展其中的每个类,因为它包含所有类都使用的一组函数。
我像这样导出我的课程:
工具.ts
export abstract class Tools {
getRandom(bytes) {
return 21 // Example
}
}
Main.ts
import * as Tools from './Tools.ts'
class Main extends Tools { // <-- I get the error from the Tools keyword here
constructor() {
super() // If not, I get an error
}
token() { // Example method
this.getRandom(2)
}
}
我得到的错误:
Type 'typeof import("[...]/tools")' is not a constructor function type
我不想在每个类中都使用new Tools(),我想直接调用该类的函数。
如何在不实例化其他类的情况下导入一个类并调用它的方法?
【问题讨论】:
标签: typescript import export