Skip to main content

No Catch Unknown Annotation

Remove redundant : unknown annotations from catch clause variables because TypeScript already defaults them to unknown.

Summary

The no-catch-unknown-annotation rule reports any catch clause parameter that has an explicit : unknown type annotation.

Since TypeScript 4.4+ defaults catch variables to unknown (when useUnknownInCatchVariables or strict is enabled), the annotation adds no value and should be removed for cleanliness.

Why Use This Rule?

  1. Eliminates noise from redundant type annotations that TypeScript already enforces.
  2. Keeps catch clauses consistent across the codebase.
  3. Reduces the chance of cargo-culting an annotation that suggests the type might be something other than unknown.

Examples

Configuration

Options

warning

ignoreFiles is an escape hatch for files where this rule genuinely does not apply. It is not intended for routine use.

OptionTypeDefaultDescription
ignoreFilesstring[][]File patterns to skip.

Autofix

This rule provides automatic fixes. Run ESLint with the --fix flag:

npx eslint --fix . --rule '@cbnventures/nova/no-catch-unknown-annotation: error'

Troubleshooting

  • Warning fires but you want to keep the annotation for documentation — It is recommended to remove it and rely on TypeScript's built-in default. The annotation is purely redundant.
  • Using an older TypeScript version — If your project uses TypeScript below 4.4 (or does not enable useUnknownInCatchVariables / strict), this rule does not apply since catch variables default to any in that configuration.