虽然whenStable
返回了一个承诺,但我不允许使用 await。
下面是我的 tsconfig
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
我在用着"typescript": "^2.1.5"
虽然whenStable
返回了一个承诺,但我不允许使用 await。
下面是我的 tsconfig
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
我在用着"typescript": "^2.1.5"
如错误消息中所述:'await' 仅允许在异步函数中使用。当你想使用await
时,你必须用async
关键字标记外部函数。
// example
const myAsyncFunction = async () => {
// ... some code
await fixture.whenStable();
// ... some code
}
当您使用async
关键字标记任何函数时,它会返回一个承诺。看一下这个问题,以更好地解释 async/await。