asyncUnnecessaryPromiseWrappers
Reports unnecessary
Promise.resolve()orPromise.reject()in async contexts.
✅ This rule is included in the ts logical preset.
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 getValue() { return Promise.resolve(42);}async function failWithError() { return Promise.reject(new Error("failed"));}promise.then(() => Promise.resolve(42));promise.catch(() => Promise.reject(new Error("error")));async function getValue() { return 42;}async function failWithError() { throw new Error("failed");}promise.then(() => 42);promise.catch(() => { throw new Error("error");});function regularFunction() { return Promise.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.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”
Made with ❤️🔥 in Boston by
Josh Goldberg and contributors.