useAwait
Diagnostic Category: lint/suspicious/useAwait
Since: v1.4.0
Sources:
- Same as:
require-await
- Same as:
@typescript-eslint/require-await
Ensure async
functions utilize await
.
This rule reports async
functions that lack an await
expression. As async
functions return a promise, the use of await
is often necessary to capture the
resolved value and handle the asynchronous operation appropriately. Without await
,
the function operates synchronously and might not leverage the advantages of async
functions.
Examples
Section titled ExamplesInvalid
Section titled Invalidcode-block.js:1:1 lint/suspicious/useAwait ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ This async function lacks an await expression.
> 1 │ async function fetchData() {
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 2 │ // Missing await
for the promise returned by fetch
> 3 │ return fetch(‘/data’);
> 4 │ }
│ ^
5 │
ℹ Remove this async modifier, or add an await expression in the function.
> 1 │ async function fetchData() {
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 2 │ // Missing await
for the promise returned by fetch
> 3 │ return fetch(‘/data’);
> 4 │ }
│ ^
5 │
ℹ Async functions without await expressions may not need to be declared async.