Skip to content

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.

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);
}
});

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.

Made with ❤️‍🔥 in Boston by Josh Goldberg and contributors.