PGT
PGT

Reputation: 2029

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

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.

Upvotes: 6

Views: 2414

Answers (1)

Bergi
Bergi

Reputation: 664559

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.

Upvotes: 5

Related Questions