Vas*_*gin 3 async-await typescript
我正在使用“async”函数,有时我忘记为内部调用添加“await”:
async function doThreeSteps () => {
await firstPromiseReturningFunc();
nonAsyncFunction();
secondPromiseReturningFunc(); //Error here! Need to wait until this call resolves
someOtherStepWhichReliesOnSuccessfullEndingOfPreviousFunction();
}
Run Code Online (Sandbox Code Playgroud)
TypeScript 应该可以警告此类错误,因为 TS 知道每个函数返回什么类型,是承诺还是值。我想让 TS 就此类情况向我发出警告。是否可以?
typescript-eslint ( https://typescript-eslint.io ) 具有“no-floating-promises”规则。它要求使用从函数返回的 Promise 来完成某些操作,例如 .then、.catch、await、赋值或 return。