Skip to content

Latest commit

 

History

History
57 lines (42 loc) · 1.07 KB

no-implicit-any-catch.md

File metadata and controls

57 lines (42 loc) · 1.07 KB

Disallow usage of the implicit any type in catch clauses (no-implicit-any-catch)

Using the any type defeats the purpose of using TypeScript. When any is used, all compiler type checks around that value are ignored.

The noImplicitAny flag in TypeScript does not cover this due to backwards compatibility reasons.

Rule Details

This rule requires an explicit type to be declared in the catch clause error argument.

The following pattern is considered a warning:

try {
  // ...
} catch (e) {
  // ...
}

The following patterns are not warnings:

try {
  // ...
} catch (e) {
  // ...
}
try {
  // ...
} catch (e) {
  // ...
}

Options

The rule accepts an options object with the following properties:

type Options = {
  // if false, disallow specifying : any as the error type as well. See also `no-explicit-any`
  allowExplicitAny: boolean;
};

const defaults = {
  allowExplicitAny: true,
};

Further Reading