İçeriğe geç

Await eksik (ARCH3029)

Anahtar typescript.async.missing-await · Önem warning · Kategori async

Promise dönen bir çağrıyı await etmeden bir boolean/değer bağlamında (if, atama, return) kullanmak hataya yol açar: Promise nesnesi her zaman truthy’dir ve gerçek sonuç hiç beklenmez.

async function ensureAccess(userId: string): Promise<void> {
if (hasPermission(userId)) { // Promise her zaman truthy
grant(userId);
}
}
async function ensureAccess(userId: string): Promise<void> {
if (await hasPermission(userId)) {
grant(userId);
}
}

Promise dönen çağrıyı değerini kullanmadan önce await ile bekleyin.