@typescript-eslint/await-thenable
Disallow await on a value that is not a promise
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.
[lint.rules]
"@typescript-eslint/await-thenable" = "error" # or "warn"Examples#
function readConfig(): string {
return "{}";
}
const config = await readConfig()Unexpected await of a non-Promise (non-"Thenable") value.;const ports = [3000, 3001];
for await (const port of ports)Unexpected for await...of of a value that is not async iterable. {
console.log(port);
}async function load(id: number): Promise<string> {
return String(id);
}
await Promise.all([load(1), 2Unexpected iterable of non-Promise (non-"Thenable") values passed to promise aggregator.]);async function readConfig(): Promise<string> {
return "{}";
}
const config = await readConfig();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:
async function resolve(value: string | Promise<string>, other: unknown) {
return [await value, await other];
}