Skip to main content

prefer-promise-reject-errors

Require using Error objects as Promise rejection reasons.

💭

This rule requires type information to run.

This rule extends the base eslint/prefer-promise-reject-errors rule. It uses type information to enforce that Promises are only rejected with Error objects.

Examples

Promise.reject('error');

const err = new Error();
Promise.reject('an ' + err);

new Promise((resolve, reject) => reject('error'));

new Promise((resolve, reject) => {
const err = new Error();
reject('an ' + err);
});
Open in Playground

Options

See eslint/prefer-promise-reject-errors's options.

How to Use

.eslintrc.cjs
module.exports = {
"rules": {
// Note: you must disable the base rule as it can report incorrect errors
"prefer-promise-reject-errors": "off",
"@typescript-eslint/prefer-promise-reject-errors": "error"
}
};

Try this rule in the playground ↗

When Not To Use It

Type checked lint rules are more powerful than traditional lint rules, but also require configuring type checked linting.

See Troubleshooting > Linting with Type Information > Performance if you experience performance degredations after enabling type checked rules.

Resources

Taken with ❤️ from ESLint core.