Skip to content

Latest commit

 

History

History
42 lines (29 loc) · 1.33 KB

no-implicit-any-catch.md

File metadata and controls

42 lines (29 loc) · 1.33 KB

Use type-safe error callbacks (no-implicit-any-catch)

This rule requires an explicit type annotation for error parameters in promise catch callbacks. It's similar to the TypeScript no-implicit-any-catch rule, but is for promises - not try/catch statements.

Rule details

Examples of incorrect code for this rule:

Promise
  .reject(new Error("Kaboom!"))
  .catch(error => console.log(error));

Examples of correct code for this rule:

Promise
  .reject(new Error("Kaboom!"))
  .catch((error: unknown) => console.log(error));

Options

This rule accepts a single option which is an object with an allowExplicitAny property that determines whether or not the error variable can be explicitly typed as any. By default, the use of explicit any is forbidden.

{
  "etc/no-implicit-any-catch": [
    "error",
    { "allowExplicitAny": true }
  ]
}

Related

Further reading