4

虽然whenStable返回了一个承诺,但我不允许使用 await。

下面是我的 tsconfig

"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
  "node_modules/@types"
],

我在用着"typescript": "^2.1.5"

4

1 回答 1

4

如错误消息中所述:'await' 仅允许在异步函数中使用。当你想使用await时,你必须用async关键字标记外部函数。

// example

const myAsyncFunction = async () => {
   // ... some code
   await fixture.whenStable();
   // ... some code
}

当您使用async关键字标记任何函数时,它会返回一个承诺。看一下这个问题,以更好地解释 async/await。

于 2017-04-21T19:40:02.923 回答