Skip to content

noUselessAwait (JavaScript)

Language JavaScript (and super languages)
biome.json
{
"linter": {
"rules": {
"nursery": {
"noUselessAwait": "error"
}
}
}
}

Disallow await on values that are never promises.

The await keyword waits for a promise to settle and returns its result. Values such as numbers, strings, arrays, functions, and the results of comparisons are never promises, so awaiting them returns the same value. The await still pauses the function until other pending work runs, which makes the code slower and suggests that the value is a promise when it isn’t.

Awaiting an array doesn’t wait for the promises inside it. Use Promise.all() or Promise.allSettled() to wait for all of them.

The rule only reports values that can be identified as non-promises from the code alone, such as literals, arrays, functions, classes, JSX, and the results of arithmetic, comparison, and unary operators.

The fix is unsafe because removing await makes the code that follows it run earlier. Biome offers the fix only when the await is the last thing its function or module runs.

await 1;
code-block.js:1:1 lint/nursery/noUselessAwait  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

ℹ This value is never a promise, so await is unnecessary.

> 1 │ await 1;
│ ^^^^^
2 │

ℹ Awaiting a value that isn't a promise returns the same value, but still delays the code that follows it.

ℹ Remove await. To wait for several promises, pass them to Promise.all() instead.

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

ℹ Unsafe fix: Remove await.

1 │ await·1;
│ ------
await [fetchUser(), fetchPosts()];
code-block.js:1:1 lint/nursery/noUselessAwait  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

ℹ This value is never a promise, so await is unnecessary.

> 1 │ await [fetchUser(), fetchPosts()];
│ ^^^^^
2 │

ℹ Awaiting a value that isn't a promise returns the same value, but still delays the code that follows it.

ℹ Remove await. To wait for several promises, pass them to Promise.all() instead.

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

ℹ Unsafe fix: Remove await.

1 │ await·[fetchUser(),·fetchPosts()];
│ ------
async function check(a, b) {
return await (a === b);
}
code-block.js:2:12 lint/nursery/noUselessAwait  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

ℹ This value is never a promise, so await is unnecessary.

1 │ async function check(a, b) {
> 2 │ return await (a === b);
│ ^^^^^
3 │ }
4 │

ℹ Awaiting a value that isn't a promise returns the same value, but still delays the code that follows it.

ℹ Remove await. To wait for several promises, pass them to Promise.all() instead.

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

ℹ Unsafe fix: Remove await.

2 │ ····return·await·(a·===·b);
│ ------
await fetchUser();
await Promise.all([fetchUser(), fetchPosts()]);
await (condition ? fetchUser() : fetchPosts());
await new Promise((resolve) => setTimeout(resolve, 100));
  • If you want to report await on any value that isn’t a promise, using type information, see useAwaitThenable.