Add setting useErrorInCatchVariables
#51390
Labels
Awaiting More Feedback
This means we'd like to hear from more people who would be helped by this feature
Suggestion
An idea for TypeScript
Suggestion
π Search Terms
catch argument type
catch error type
useUnknownInCatchVariables
β Viability Checklist
My suggestion meets these guidelines:
β Suggestion
π Motivating Example
This would be the same kind of setting as
useUnknownInCatchVariables
, except simply replace "Unknown" with "Error".π» Use Cases
Yes, we all know that a maniac could decide to throw a string if they really wanted to--but if that's happening in your project you've got much bigger problems than type safety. TypeScript is about enforcing a contract, so why not allow users to say "all thrown objects will extend
Error
"? This will reduce annoying boilerplate/explicit casts incatch
blocks when you just want to access general error properties, or passerr
to a function that expects anError
.Obviously this is related to other issues (for example, #20024), but I'm not talking about allowing type annotations in catch variables. Just automatically assuming type
Error
and nothing more.The text was updated successfully, but these errors were encountered: