我嘗試使用WebStorm IDE在typescript(ES6)中編寫測試。例如爲:WebStorm,ES5/ES3中的異步函數或方法需要'Promise'構造函數
// Imports...
describe('Message',() => {
const server = express();
server.use(bodyParser.json());
const messageService = { findAll:() => ['test'] };
beforeAll(async() => {
const module = await Test.createTestingModule({
modules: [MessageModule],
})...
});
// Tests...
});
然而WebStorm IDE顯示以下錯誤在async() =>
TS2705:在ES5/ES3異步函數或方法需要無極 構造。確保你有一個Promise 構造函數的聲明或者在你的--lib選項中包含ES2015。
我tsconfig.json
:
{
"compilerOptions": {
"module": "commonjs",
"declaration": false,
"noImplicitAny": false,
"removeComments": true,
"noLib": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es6",
"sourceMap": true,
"allowJs": true,
"outDir": "./dist"
},
"include": [
"src/**/*"
],
"exclude": [
"node_modules",
"**/*.spec.ts"
]
}
我讀ts An async function or method in ES5/ES3 requires the 'Promise' constructor並嘗試添加
"lib": [ "es2015" ]
但是它不具有任何影響。任何想法有什麼不對?
include/exclude是問題,謝謝lena :) –