我正在编写一个NodeJS打字稿项目。假设我有以下文件:
class MyArray extends Array {
myCustomMethod() { /* do something */ }
}
但是,当我这样做
let myarray = new MyArray();
myarray.myCustomMethod();
我知道
TypeError: myarray.myCustomMethod is not a function
因此,我尝试将打字稿module
更改为es6(以便保留class extends
语法),但是随后使用了import
和export
关键字,而NodeJS本身不支持。
有没有一种方法可以强制打字稿编译器使用requirejs但还要使用es6?
是我的坏事,我想念什么吗?
答案 0 :(得分:0)
TypeScript的--module
选项(也为-m
)使您可以指定输出的模块系统。 "CommonJS"
是使用require
的变体。 project configuration options documentation中的详细信息。
例如,在tsconfig.json
中,"module": "CommonJS"
与"target": "ES2015"
(或"ES2020"
或"ESNext"
等组合)应使用{{1 }}和require
语法。