Skip to content

asyncUnnecessaryPromiseWrappers

Reports unnecessary Promise.resolve() or Promise.reject() in async contexts.

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

Wrapping a return value in Promise.resolve() in an async function or a promise callback is unnecessary because return values are already wrapped in a Promise. Similarly, returning an error wrapped in Promise.reject() is equivalent to throwing the error. This applies to yield expressions in async generators as well.

async function
function getValue(): Promise<number>
getValue
() {
return
var Promise: PromiseConstructor

Represents the completion of an asynchronous operation

Promise
.
PromiseConstructor.resolve<number>(value: number): Promise<number> (+2 overloads)

Creates a new resolved promise for the provided value.

@paramvalue A promise.

@returnsA promise whose internal state matches the provided promise.

resolve
(42);
}
async function
function failWithError(): Promise<never>
failWithError
() {
return
var Promise: PromiseConstructor

Represents the completion of an asynchronous operation

Promise
.
PromiseConstructor.reject<never>(reason?: any): Promise<never>

Creates a new rejected promise for the provided reason.

@paramreason The reason the promise was rejected.

@returnsA new rejected Promise.

reject
(new
var Error: ErrorConstructor
new (message?: string, options?: ErrorOptions) => Error (+1 overload)
Error
("failed"));
}
const promise: any
promise
.
any
then
(() =>
var Promise: PromiseConstructor

Represents the completion of an asynchronous operation

Promise
.
PromiseConstructor.resolve<number>(value: number): Promise<number> (+2 overloads)

Creates a new resolved promise for the provided value.

@paramvalue A promise.

@returnsA promise whose internal state matches the provided promise.

resolve
(42));
const promise: any
promise
.
any
catch
(() =>
var Promise: PromiseConstructor

Represents the completion of an asynchronous operation

Promise
.
PromiseConstructor.reject<never>(reason?: any): Promise<never>

Creates a new rejected promise for the provided reason.

@paramreason The reason the promise was rejected.

@returnsA new rejected Promise.

reject
(new
var Error: ErrorConstructor
new (message?: string, options?: ErrorOptions) => Error (+1 overload)
Error
("error")));

This rule is not configurable.

If you have a codebase that intentionally uses Promise.resolve() and Promise.reject() for consistency across async and non-async functions, you may want to disable this rule.

Made with ❤️‍🔥 around the world by the Flint team and contributors.