问题
In TypeScript, it is possible to check and warn the developer if they are calling an async
function synchronously.
For those that want less overhead and using node.js v9.0+, is it possible to have any linter give us a warning if we have something like this?
async function foo() {
return;
}
var result = foo(); // warning right here because there is no await
The reason being is that it is not apparently if a function is returning a promise/is await unless we explicitly name it fooAsync
, look into the implementation, or assume everything is async. Or maybe devs messed up and forgot to write await
.
Just want a warning to catch errors at dev time and not runtime.
回答1:
No, that is not possible. As you say, it requires type inference or at least annotations to decide whether a function will return a promise. That's what a typechecker like the TypeScript compiler does, not a linter.
来源:https://stackoverflow.com/questions/50047487/lint-warning-for-invoking-an-async-function-without-then-or-await-without