我尝试使用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 :) –