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.

const
const result: Promise<unknown>
result
= new
var Promise: PromiseConstructor
new <unknown>(executor: (resolve: (value: unknown) => void, reject: (reason?: any) => void) => void) => Promise<unknown>

Creates a new Promise.

@paramexecutor A callback used to initialize the promise. This callback is passed two arguments: a resolve callback used to resolve the promise with a value or the result of another promise, and a reject callback used to reject the promise with a provided reason or error.

Promise
(async (
resolve: (value: unknown) => void
resolve
,
reject: (reason?: any) => void
reject
) => {
const
const data: Response
data
= await
function fetch(input: string | URL | Request, init?: RequestInit): Promise<Response>
fetch
("/api");
resolve: (value: unknown) => void
resolve
(
const data: Response
data
);
});
new
var Promise: PromiseConstructor
new <unknown>(executor: (resolve: (value: unknown) => void, reject: (reason?: any) => void) => void) => Promise<unknown>

Creates a new Promise.

@paramexecutor A callback used to initialize the promise. This callback is passed two arguments: a resolve callback used to resolve the promise with a value or the result of another promise, and a reject callback used to reject the promise with a provided reason or error.

Promise
(async function (
resolve: (value: unknown) => void
resolve
,
reject: (reason?: any) => void
reject
) {
try {
resolve: (value: unknown) => void
resolve
(await
const asyncOperation: any
asyncOperation
());
} catch (
function (local var) error: unknown
error
) {
reject: (reason?: any) => void
reject
(
function (local var) error: unknown
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 ❤️‍🔥 around the world by the Flint team and contributors.