Lint warning for invoking an async function without `.then()` or `await` without TypeScript

限于喜欢 提交于 2021-02-16 17:56:16

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!