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: Promise<unknown>
promise
.
Promise<unknown>.then<number, never>(onfulfilled?: ((value: unknown) => number | PromiseLike<number>) | null | undefined, onrejected?: ((reason: any) => PromiseLike<never>) | null | undefined): Promise<number>

Attaches callbacks for the resolution and/or rejection of the Promise.

@paramonfulfilled The callback to execute when the Promise is resolved.

@paramonrejected The callback to execute when the Promise is rejected.

@returnsA Promise for the completion of which ever callback is executed.

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: Promise<unknown>
promise
.
Promise<unknown>.catch<never>(onrejected?: ((reason: any) => PromiseLike<never>) | null | undefined): Promise<unknown>

Attaches a callback for only the rejection of the Promise.

@paramonrejected The callback to execute when the Promise is rejected.

@returnsA Promise for the completion of the callback.

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.