You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hey, I've noticed that the type of a caught error is any. Should it be unknown instead?
Use Cases
I think the any type makes no real sense in terms of helping process the errors. The unknown has been designed in order to help devs ensure that they narrow down the types properly when the real type is unclear. I believe this type would fit perfectly to the catch statement.
Examples
try{somethingThatFailsAndProbablyThrowsAnError();}catch(e){// e is of unknown type instead of any type, to make devs narrow down the type// when they want to do something with the error// We have to narrow down the type, before using the valueif(einstanceofError){// ... okay}}
Checklist
My suggestion meets these guidelines:
This wouldn't be a breaking change in existing TypeScript/JavaScript code
This wouldn't change the runtime behavior of existing JavaScript code
This could be implemented without emitting different JS based on the types of the expressions
This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
Search Terms
catch
unknown
any
catch statement
catch type
Suggestion
Hey, I've noticed that the type of a caught error is
any
. Should it beunknown
instead?Use Cases
I think the
any
type makes no real sense in terms of helping process the errors. Theunknown
has been designed in order to help devs ensure that they narrow down the types properly when the real type is unclear. I believe this type would fit perfectly to the catch statement.Examples
Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: