Skip to content

Rule proposal: always use type (error: unknown) => void with promise.catch #7526

@NotWoods

Description

@NotWoods

Before You File a Proposal Please Confirm You Have Done The Following...

My proposal is suitable for this project

  • My proposal specifically checks TypeScript syntax, or it proposes a check that requires type information to be accurate.
  • My proposal is not a "formatting rule"; meaning it does not just enforce how code is formatted (whitespace, brace placement, etc).
  • I believe my proposal would be useful to the broader TypeScript community (meaning it is not a niche proposal).

Description

TypeScript has the useUnknownInCatchVariables option to use unknown with catch clauses instead of any. However, promise.catch is stuck with using an any type no matter how you configure this option.

I'd like a rule to enforce using the type unknown with the caught error handler for promises. This could either use type inference or just lint every method named .catch.

Fail Cases

promise.catch((error) => { ... });
promise.catch((error: Error) => { ... });
promise.catch((error: any) => { ... });

Pass Cases

promise.catch((error: unknown) => { ... });

Additional Info

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issueenhancement: new plugin ruleNew rule request for eslint-pluginlocked due to agePlease open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.package: eslint-pluginIssues related to @typescript-eslint/eslint-plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions