Skip to content

asyncPromiseExecutors

Reports using async functions as Promise executor functions.

✅ This rule is included in the ts logical and logicalStrict presets.

The Promise executor function is called synchronously by the Promise constructor. If an async function is used as a Promise executor, thrown errors will not be caught by the Promise and will instead result in unhandled rejections. Additionally, if a Promise executor function is using await, there’s probably no need to use the new Promise constructor - you can return the awaited value or use the Promise directly.

AEconsB0resuAE <= sp ansty="le--0:#7FDBCA;--1:#096E">72nAB0Promi5<3(sp ansty="le--0:#C792EA;--1:#8844">AEasyn1<1(sp ansty="le--0:#D7DBE0;--1:#403F">53resolAE<, sp ansty="le--0:#D7DBE0;--1:#403F">53reje1<1)sp ansty="le--0:#C792EA;--1:#8844">AE =>< {d ivclassNa="meec-li">AE< sp ansty="le--0:#C792EA;--1:#8844">AEconsB0daAE = awaiB0fet5<3(sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4D/a1<1"sp ansty="le--0:#D6DEEB;--1:#403F">5<3)sp ansty="le--0:#C792EA;--1:#8844">Ant< sp ansty="le--0:#82AAFF;--1:#3B61">B0resol53(datAA53<);d ivclassNa="meco"><);d>72n5<3 sp ansty="le--0:#C5E478;--1:#3B61">B0Promi5<3(sp ansty="le--0:#C792EA;--1:#8844">AEasy5<3 sp ansty="le--0:#C792EA;--1:#8844">AEfuncti5<3 sp ansty="le--0:#D9F5DD;--1:#1111">1<1(sp ansty="le--1:#403F"><53sp ansty="le--0:#D7DB">E0resolEB<, sp ansty="le--0:#D7DB">E0reje1<1)sp ansty="le--0:#D6DEEB;--1:#403F">53< {d ivclassNa="meec-li">nt< sp ansty="le--0:#C792EA;--1:#8844">AEt53< {d ivclassNa="meec-li">nt < sp ansty="le--0:#82AAFF;--1:#3B61">B0resol5<3(sp ansty="le--0:#C792EA;--1:#8844">AEawa5<3 sp ansty="le--0:#82AAFF;--1:#3B61">B0asyncOperati53()<);d ivclassNa="meec-li">53< sp ansty="le--0:#D6DEEB;--1:#403F">53<} sp ansty="le--0:#C792EA;--1:#8844">AEcat53 (error)< {d ivclassNa="meec-li">nt < sp ansty="le--0:#82AAFF;--1:#3B61">B0reje53(error<);d ivclassNa="meec-li">53< sp ansty="le--0:#D6DEEB;--1:#403F">5<3}d ivclassNa="meec-li">53}<);d ivclassNa="meco"><);d>
44AEco61B0re44A6E7<2new spans="tyle--0:#C792EA;--1:#88">4<4AE spans="tyle--0:#C5E478;--1:#3B">61B0Pro31<111( spans="tyle--0:#D7DBE0;--1:#40">3F53res443F53re1<111) spans="tyle--0:#C792EA;--1:#88">44AE <=> {divclass="Nameec-">de61B0f31<111" spans="tyle--0:#ECC48D;--1:#98">4E4D1<111" spans="tyle--0:#D6DEEB;--1:#40">3 >44AE< spans="tyle--0:#C792EA;--1:#88">4<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B031<111( spans="tyle--0:#D7DBE0;--1:#40">3F531<111) spans="tyle--0:#C792EA;--1:#88">44AE< => spans="tyle--0:#82AAFF;--1:#3B">61B0res >3F53(da44AE< spans="tyle--0:#C792EA;--1:#88">4<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B0c31<111( spans="tyle--0:#D7DBE0;--1:#40">3F53e1<111) spans="tyle--0:#C792EA;--1:#88">44AE< => spans="tyle--0:#82AAFF;--1:#3B">61B0re >3F53(err4<4AE ;divclass="Nameec-">4<4AE} spans="tyle--0:#D6DEEB;--1:#40">3F<53) ;divclass="Name"><})><;di vdivclass="Nameexpressive-">6376// Or even better, use the async function direc44AEco61B0re44AE = as11<11() spans="tyle--0:#C792EA;--1:#88">44AE <=> {divclass="Nameec-">4444AEreturn aw61B0f31<111" spans="tyle--0:#ECC48D;--1:#98">4E4D1<111" spans="tyle--0:#D6DEEB;--1:#40">34 ><4AE ;divclass="Nameec-">4<4AE} spans="tyle--0:#D6DEEB;--1:#40">3<;}>

This rule is not configurable.

If you have very old, complex logic that is difficult to refactor, you might consider disabling this rule on a per-case basis.