Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Typescript,自动等待所有承诺返回函数调用_Typescript_Async Await - Fatal编程技术网

Typescript,自动等待所有承诺返回函数调用

Typescript,自动等待所有承诺返回函数调用,typescript,async-await,Typescript,Async Await,我正在使用“async”函数,有时我会忘记为内部调用添加“wait”: async function doThreeSteps () => { await firstPromiseReturningFunc(); nonAsyncFunction(); secondPromiseReturningFunc(); //Error here! Need to wait until this call resolves someOtherStepWhichReli

我正在使用“async”函数,有时我会忘记为内部调用添加“wait”:

async function doThreeSteps () => {
    await firstPromiseReturningFunc();
    nonAsyncFunction();
    secondPromiseReturningFunc(); //Error here! Need to wait until this call resolves
    someOtherStepWhichReliesOnSuccessfullEndingOfPreviousFunction();
}
TypeScript应该可以警告此类错误,因为TS知道每个函数返回的是什么类型,是承诺还是值。 我想提醒一下这种情况。有可能吗?

TSLint()有“无浮动承诺”规则。它要求使用从函数返回的承诺来完成某些事情,例如.then、.catch、wait、assignment或return


还有一个TypeScript问题:

如果您定义了
x3
的类型,编译器应该抛出一个错误始终将类型添加到变量中。消除了大多数错误。抱歉,现在已更新。您关于变量类型的建议是100%正确的,但不适用于更新的问题。