在我的Typescript中,我使用的是导入函数,如下所述:
https://github.com/Microsoft/TypeScript/issues/12933
所以我的代码就像:
import("../myScriptToBeImported").then((module) => {
this.dosomethingWithModule(module);
}).catch(this.doSomethingWithError.bind(this));
我在使用Webpack的Visual Studio中运行此作为MVC项目的一部分。 Webpack编译Typescript没有任何错误,项目运行正常,但对于上面的行,以下错误总是在Visual Studio中显示:
我正在使用Typescript版本2.4.2。我怎样才能摆脱这些错误?
有关信息,我的tsconfig文件如下所示:
{
"compilerOptions": {
"module": "esnext",
"moduleResolution": "node",
"noEmitOnError": true,
"strict": true,
"removeComments": false,
"sourceMap": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [ "es6", "dom" ],
"baseUrl": ".",
"experimentalDecorators": true,
"emitDecoratorMetadata": true
},
"exclude": [
"node_modules",
"wwwroot"
],
"compileOnSave": false,
"buildOnSave": false
}
答案 0 :(得分:1)
函数式import
还不是JS模块规范的一部分。您需要在module
中将"esnext"
设置为tsconfig.json
才能使用它。
如果您已经这样做了,问题可能在于Visual Studio - 确保您的项目配置为使用正确版本的TypeScript编译器。