![](/img/trans.png)
[英]TS2705 Error in Visual Studio: An async function or method in ES5/ES3 requires the 'Promise' constructor
[英]WebStorm hints me the TS error (TS2705) when I use jest(ts-jest async/await test)
軟件包:jest ts-jest @ types / jest
IDE:WebStorm
當我使用開玩笑的異步測試時,出現無法解決的TS錯誤(TS2705)。 但是此提示不會影響jest
命令。
當我使用最小的測試時,會出現相同的錯誤:
import {} from 'jest';
test('async test',async ()=>{
});
jest.config.js
module.exports = {
"transform": {
"^.+\\.tsx?$": "ts-jest"
},
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json",
"node"
],
globals:{
'ts-jest':{
// I have the same behavior when I delete this line
"tsConfigFile": "./tsconfig.json"
}
}
};
tsconfig.json
{
"compilerOptions": {
"types": [
"node"
],
"module": "commonjs",
"target": "es2017",
"lib": [
"es2015",
"es2016",
"esnext.asynciterable"
],
"noImplicitAny": false,
"noImplicitThis": false,
"inlineSourceMap": true,
"rootDirs": ["."],
"outDir":"./dist",
"experimentalDecorators":true,
"emitDecoratorMetadata": true,
"moduleResolution": "node",
"watch":false
},
"include":[
"./app/**/*.ts",
"./config/**/*.ts",
"./app.ts",
"./preload.ts"
],
"exclude": [
"./dist/**/*.*"
]
}
如何解決此IDE錯誤提示?
如果在首選項|選項卡中啟用了TypeScript服務。 語言和框架| TypeScript ,它使用包含在其中的最近的tsconfig.json
當前文件,從文件dir到項目根目錄掃描文件夾。 如果未找到包含當前文件的tsconfig.*.json
文件, tsconfig.*.json
默認配置用於文件插入。 請注意您的根tsconfig.json
的“ include ”部分:
"include":[
"./app/**/*.ts",
"./config/**/*.ts",
"./app.ts",
"./preload.ts"
],
您的規范文件所在的“測試”目錄未包含在TypeScript項目中。 請參閱tsconfig.json文檔 :
如果未指定“文件”和“包含”,則編譯器默認將所有TypeScript(.ts,.d.ts和.tsx)文件包括在包含目錄和子目錄中,但使用“ exclude”屬性排除的文件除外。 如果指定了“文件”或“包含”屬性,則編譯器將改為包含這兩個屬性所包含的文件的並集。
因此,找不到適合您的spec文件的tsconfig.json
文件(您必須在typeScript控制台中看到警告“未找到根tsconfig.json”)。 結果,使用了不包含"es2015"
庫的默認編譯器首選項-因此出錯。 在根配置中包含測試文件,或在“ tests”目錄中添加具有適當設置的單獨tsconfig.json
此問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.