@typescript-eslint/await-thenable

Disallow await on a value that is not a promise

has suggestionsneeds types

Also called typescript-eslint/await-thenable, typescript/await-thenable

await on a value that has no then method gives back the same value one tick later. It's usually a mistake. Either the function was never async, or you forgot to call it.

The same goes for for await...of over something that isn't async iterable, await using with something that isn't async disposable, and values that aren't promises in the array passed to Promise.all, Promise.allSettled, Promise.any, or Promise.race.

bun lint --type-aware turns this rule on in TypeScript files.

Configure#

Off by default. This rule needs types, so turning it on makes bun lint type check your code first.

bunfig.toml
[lint.rules]
"@typescript-eslint/await-thenable" = "error" # or "warn"

Examples#

example.ts1 problem
function readConfig(): string {
  return "{}";
}

const config = await readConfig();
example.ts1 problem
const ports = [3000, 3001];

for await (const port of ports) {
  console.log(port);
}
example.ts1 problem
async function load(id: number): Promise<string> {
  return String(id);
}

await Promise.all([load(1), 2]);
example.tsNo problems
async function readConfig(): Promise<string> {
  return "{}";
}

const config = await readConfig();
example.tsNo problems
const ports = [3000, 3001];

for (const port of ports) {
  console.log(port);
}

You can await a value that may or may not be a promise, and you can await any and unknown:

example.tsNo problems
async function resolve(value: string | Promise<string>, other: unknown) {
  return [await value, await other];
}