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.
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) {
// ...
}
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,
};
- The original issue report for allowing
: unknown
in error clauses: microsoft/TypeScript#36775