在node.js中我可以这样做:
class MyClass{
data(){
return [
require('this-module'),
require('another-module),
require('that-module),
];
}
}
在打字稿中我可以写:
import * as ThisModule from 'this-module'
import * as AnotherModule from 'another-module'
import * as ThatModule from 'that-module'
class MyClass{
data():MyModuleTypeArray{
return [
ThisModule,
AnotherModule,
ThatModule
];
}
}
但在那个解决方案中,我必须每次写下3个名字。
我的问题:我可以在Typescript中编写内联包含的代码,还是以其他方式编写我不需要写3次名称的代码(或者使用辅助变量)?
当然我可以写require
,但require
会返回any
。我想要进行类型检查。