asyncUnnecessaryPromiseWrappers
Reports unnecessary
Promise.resolve()orPromise.reject()in async contexts.
✅ This rule is included in the tslogicalandlogicalStrictpresets.
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.
Examples
Section titled “Examples”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.
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.
reject(new var Error: ErrorConstructornew (message?: string) => Error
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.
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.
reject(new var Error: ErrorConstructornew (message?: string) => Error
Error("error")));async function function getValue(): Promise<number>
getValue() { return 42;}async function function failWithError(): Promise<void>
failWithError() { throw new var Error: ErrorConstructornew (message?: string) => Error
Error("failed");}const promise: any
promise.any
then(() => 42);const promise: any
promise.any
catch(() => { throw new var Error: ErrorConstructornew (message?: string) => Error
Error("error");});function function regularFunction(): Promise<number>
regularFunction() { 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.
resolve(42);}Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”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.