asyncPromiseExecutors
Reports using async functions as Promise executor functions.
✅ This rule is included in the ts logical
preset.
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.
Examples
Section titled “Examples”const result = new Promise(async (resolve, reject) => { const data = await fetch("/api"); resolve(data);});
new Promise(async function (resolve, reject) { try { resolve(await asyncOperation()); } catch (error) { reject(error); }});
const result = new Promise((resolve, reject) => { fetch("/api") .then((data) => resolve(data)) .catch((error) => reject(error));});
// Or even better, use the async function directly:const result = async () => { return await fetch("/api");};
Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”If you have very old, complex logic that is difficult to refactor, you might consider disabling this rule on a per-case basis.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- Biome:
noAsyncPromiseExecutor
- Deno:
no-async-promise-executor
- ESLint:
no-async-promise-executor
- Oxlint:
eslint/no-async-promise-executor
Made with ❤️🔥 in Boston by
Josh Goldberg and contributors.