Skip to content

catchCallbackTypes

Reports Promise catch callback parameters that are not typed as unknown.

✅ This rule is included in the ts logical presets.

TypeScript’s useUnknownInCatchVariables compiler option only affects synchronous catch clauses, not Promise callbacks. Promise rejection values can be anything, so the callback parameter in .catch() and the second argument to .then() should be typed as unknown to force proper type narrowing before use.

Without an explicit unknown type annotation, the catch callback parameter is implicitly typed as any, undermining type safety.

Promise.resolve().catch((error) => {
console.log(error);
});
Promise.resolve().catch((error: any) => {
console.log(error);
});
Promise.resolve().then(
() => {},
(error) => {
console.log(error);
},
);

This rule is not configurable.

If your codebase is not yet able to enable useUnknownInCatchVariables, it may be similarly difficult to enable this rule. If you have modified the global type declarations to make then() and catch() callbacks use the unknown type without an explicit type annotation, you do not need this rule.

Made with ❤️‍🔥 in Boston by Josh Goldberg and contributors.