Skip to main content

no-implicit-any-catch

Require explicit error parameter typing in Promise rejection callbacks.

Targeted pattern scopeโ€‹

โš ๏ธ This rule requires type information to run. Configure type-aware linting (parserOptions.project or projectService) before enabling it.

This rule targets Promise rejection callbacks in:

  • .catch(callback)
  • .then(onFulfilled, onRejected) (second argument)

Only callbacks associated with Promise-like receivers are checked.

What this rule reportsโ€‹

Promise rejection callbacks often default the error parameter to implicit any. That weakens type safety and makes unsafe property access easy to miss.

This rule enforces explicit typing for Promise rejection callback parameters in .catch(...) and the rejection handler position of .then(...).

By default:

  • Implicit any is reported and auto-fixed to unknown.
  • Explicit any is reported and auto-fixed to unknown.
  • Narrower types (for example string) are reported with a safe suggestion to change to unknown.

Why this rule existsโ€‹

It prevents unsafe assumptions about rejection values and encourages explicit narrowing before property access.

โŒ Incorrectโ€‹

Promise.reject(new Error("Boom")).catch((error) => {
console.error(error);
});
Promise.reject(new Error("Boom")).catch((error: any) => {
console.error(error);
});

โœ… Correctโ€‹

Promise.reject(new Error("Boom")).catch((error: unknown) => {
if (error instanceof Error) {
console.error(error.message);
}
});

Behavior and migration notesโ€‹

This rule is fixable and also provides explicit suggest entries.

Automatic fixes annotate missing/any parameters as unknown. For already narrowed annotations, a safe suggestion is provided instead of forced rewrite.

Optionsโ€‹

type Options = [
{
allowExplicitAny?: boolean;
}?,
];

Default:

[{}];

allowExplicitAnyโ€‹

Set allowExplicitAny: true to allow explicit any annotations in Promise rejection callbacks.

import etcMisc from "eslint-plugin-etc-misc";

export default [
{
plugins: { "etc-misc": etcMisc },
rules: {
"etc-misc/no-implicit-any-catch": [
"error",
{
allowExplicitAny: true,
},
],
},
},
];

Additional examplesโ€‹

Promise.resolve(1).then(
(value) => value,
(error: string) => {
console.error(error);
}
);
// โŒ reported as narrowed type, with suggestion to use unknown

Promise.resolve(1).catch((error: unknown) => {
if (error instanceof Error) {
console.error(error.message);
}
});
// โœ… valid

ESLint flat config exampleโ€‹

import etcMisc from "eslint-plugin-etc-misc";

export default [
{
plugins: { "etc-misc": etcMisc },
rules: {
"etc-misc/no-implicit-any-catch": "error",
},
},
];

When not to use itโ€‹

Disable this rule if your codebase intentionally relies on broad rejection parameter typing and you do not want to enforce explicit unknown handling.

Package documentationโ€‹

Rule catalog ID: R026

Further readingโ€‹

Adoption resourcesโ€‹

  • Start at warning level in CI, then move to error after cleanup.
  • Use focused codemods/autofix batches per package or directory.