Aller au contenu

Unnecessary Async Await (ARCH3025)

Ce contenu n’est pas encore disponible dans votre langue.

Key typescript.async.unnecessary-async-await · Severity info · Category async

An async function whose only await is on the single returned expression adds a state-machine/microtask hop with no benefit. The promise can be returned directly.

async function getUser(id: string): Promise<User> {
return await db.users.findById(id);
}
function getUser(id: string): Promise<User> {
return db.users.findById(id);
}

Drop the async/await pair and return the promise directly; keep the await only if it is inside a try/catch.