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">72n= sp>AB0Promi5<3(sp ansty="le--0:#C792EA;--1:#8844">AEasyn3(sp>1<1(sp ansty="le--0:#D7DBE0;--1:#403F">53resol1(sp>AE<, sp ansty="le--0:#D7DBE0;--1:#403F">53reje, sp>1<1)sp ansty="le--0:#C792EA;--1:#8844">AE =>1)sp>< {d ivclassNa="meec-li">AE< sp ansty="le--0:#C792EA;--1:#8844">AEcons sp>B0daAE = awaiB0fet5<3(sp ansty="le--0:#D9F5DD;--1:#1111">13(sp><1"sp ansty="le--0:#ECC48D;--1:#984E">4D/a1"sp>1<1"sp ansty="le--0:#D6DEEB;--1:#403F">51"sp><3)sp ansty="le--0:#C792EA;--1:#8844">A3)sp> {d>nt< sp ansty="le--0:#82AAFF;--1:#3B61">B0resol sp>53(datAA53<);d ivclassNa="meco"> { const data = await fetch("/api"); resolve(data);}"><);d>);d>);d>72n5<3 sp ansty="le--0:#C5E478;--1:#3B61">B0Promi3 sp>5<3(sp ansty="le--0:#C792EA;--1:#8844">AEasy3(sp>5<3 sp ansty="le--0:#C792EA;--1:#8844">AEfuncti3 sp>5<3 sp ansty="le--0:#D9F5DD;--1:#1111">13 sp><1(sp ansty="le--1:#403F"><53sp ansty="le--0:#D7DB">E0resol53sp>EB<, sp ansty="le--0:#D7DB">E0reje, sp>1(sp>1<1)sp ansty="le--0:#D6DEEB;--1:#403F">531)sp>< {d ivclassNa="meec-li">nt< sp ansty="le--0:#C792EA;--1:#8844">AEt sp>53 {d>< {d ivclassNa="meec-li">nt < sp ansty="le--0:#82AAFF;--1:#3B61">B0resol sp>5<3(sp ansty="le--0:#C792EA;--1:#8844">AEawa3(sp>5<3 sp ansty="le--0:#82AAFF;--1:#3B61">B0asyncOperati3 sp>53() {d><);d ivclassNa="meec-li">53< sp ansty="le--0:#D6DEEB;--1:#403F">53 sp><} sp ansty="le--0:#C792EA;--1:#8844">AEcat} sp>53 (error));d>< {d ivclassNa="meec-li">nt < sp ansty="le--0:#82AAFF;--1:#3B61">B0reje sp>53(error {d><);d ivclassNa="meec-li">53< sp ansty="le--0:#D6DEEB;--1:#403F">5 sp>);d><3}d ivclassNa="meec-li">53}3}d><);d ivclassNa="meco"><);d>);d>);d> 44AEco61B0re44A6E7<2new spans="tyle--0:#C792EA;--1:#88">42new><4AE spans="tyle--0:#C5E478;--1:#3B">61B0Pro4AE >31<111( spans="tyle--0:#D7DBE0;--1:#40">3F53res111(>443F53re1<111) spans="tyle--0:#C792EA;--1:#88">44AE 111)><=> {divclass="Nameec-">de61B0f31<111" spans="tyle--0:#ECC48D;--1:#98">4E4D111">1/api><111" spans="tyle--0:#D6DEEB;--1:#40">3111">=> >44AE< spans="tyle--0:#C792EA;--1:#88">4 ><4AE. spans="tyle--0:#82AAFF;--1:#3B">61B04AE.>31<111( spans="tyle--0:#D7DBE0;--1:#40">3F53111(>1<111) spans="tyle--0:#C792EA;--1:#88">44AE111)>< => spans="tyle--0:#82AAFF;--1:#3B">61B0res => >3F53(da44AE< spans="tyle--0:#C792EA;--1:#88">4 ><4AE. spans="tyle--0:#82AAFF;--1:#3B">61B0c4AE.>31<111( spans="tyle--0:#D7DBE0;--1:#40">3F53e111(>1<111) spans="tyle--0:#C792EA;--1:#88">44AE111)>< => spans="tyle--0:#82AAFF;--1:#3B">61B0re => >3F53(err4<4AE ;divclass="Nameec-">4<4AE} spans="tyle--0:#D6DEEB;--1:#40">3F4AE}>4AE><53) ;divclass="Name"> { fetch("/api") .then((data) => resolve(data)) .catch((error) => reject(error));"><})>})>53)><;di vdivclass="Nameexpressive-">6376// Or even better, use the async function direc44AEco61B0re44AE = as11<11() spans="tyle--0:#C792EA;--1:#88">44AE 11()><=> {divclass="Nameec-">4444AEreturn aw61B0f31<111" spans="tyle--0:#ECC48D;--1:#98">4E4D111">1/api><111" spans="tyle--0:#D6DEEB;--1:#40">3111">4=> ><4AE ;divclass="Nameec-">4<4AE} spans="tyle--0:#D6DEEB;--1:#40">34AE}>4AE> { return await fetch("/api")"><;}>;}>;di>
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.