-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error in catch clause should be unknown #26174
Comments
I'd love to see this as well. I just made a PR to get this for Reacts |
I want to enable this change by a compiler option. Or want to declare only unknown type like |
I believe the default inferred type for please see: typescript-eslint/typescript-eslint#3348 |
It appears this has been implemented in #41013 and should likely be closed. |
Search Terms
catch unknown type
Suggestion
Today I had another situation where I would have wanted #13219, but a less complex feature that would have prevented the bug as well would have been if the error in
catch
clauses had the newunknown
type instead ofany
, forcing me to narrow it down before accessing properties.Ideally this would be the same for the
Promise
rejection type.Use Cases
Making error handling more type safe. Currently
any
prevents type narrowing.Examples
This is a real world example of a bug:
Very easy to miss in code review - it should have been
err.error.errors
. This is an error returned by a real API.Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: