Upv*_*ote 10 async-await webstorm typescript
我尝试使用WebStorm IDE在typescript(ES6)中编写测试.例如:
// Imports...
describe('Message', () => {
const server = express();
server.use(bodyParser.json());
const messageService = { findAll: () => ['test'] };
beforeAll(async () => {
const module = await Test.createTestingModule({
modules: [MessageModule],
})...
});
// Tests...
});
Run Code Online (Sandbox Code Playgroud)
但是,WebStorm IDE显示以下错误 async () =>
TS2705:ES5/ES3中的异步函数或方法需要Promise构造函数.确保您有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"
]
}
Run Code Online (Sandbox Code Playgroud)
我读过ES5/ES3中的异步函数或方法需要'Promise'构造函数并尝试添加
"lib": [ "es2015" ]
Run Code Online (Sandbox Code Playgroud)
但它没有任何影响.有什么想法有什么不对吗?
len*_*ena 17
添加
"lib": [ "es2015" ]
Run Code Online (Sandbox Code Playgroud)
到tsconfig.json应该解决这个问题.但是,您的spec文件似乎未包含在tsconfig.json中(检查"include":[]和"exclude":[]值).因此,Typescript服务必须为您的文件使用不同的tsconfig.json(如果没有找到包含您的规范的tsconfig.json文件,则可能是默认文件)要解决此问题,请确保lib在config中指定属性用于您的spec文件处理
Fra*_*rzi 11
我在IntelliJ中遇到此问题,并通过更改IDE设置解决了:
设置 -> 语言和框架 -> TypeScript
然后在“选项”字段中添加:
--lib es2015
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11394 次 |
| 最近记录: |