-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
infer err
in catch(err) {}
as unknown
#43960
Comments
See #41016 |
I think this should not be the default behavior since it would bring breaking changes. |
@gerardolima Why do you believe changing the default type to a more restrictive one won't be a breaking change?
|
hey, @MartinJohns, I think this would enforce correct type checks on optimistic code. Nevertheless, this issue was flagged as duplicate (I think related to #41016). |
Not sure what you mean?Sent using the mobile mail appOn 06/05/2021 at 2:10 PM, Gerardo Lima wrote:
From: "Gerardo Lima" ***@***.***>Date: 6 May 2021To: "microsoft/TypeScript" ***@***.***>Cc: "Subscribed" ***@***.***>Subject: Re: [microsoft/TypeScript] infer `err` in `catch(err) {}` as `unknown` (#43960)
hey, @MartinJohns, I think this would enforce correct type checks on optimistic code. Nevertheless, this issue was flagged as duplicate (I think related to #41016).
—You are receiving this because you are subscribed to this thread.Reply to this email directly, view it on GitHub, or unsubscribe.
[
{
***@***.***": "http://schema.org",
***@***.***": "EmailMessage",
"potentialAction": {
***@***.***": "ViewAction",
"target": "#43960 (comment)",
"url": "#43960 (comment)",
"name": "View Issue"
},
"description": "View this Issue on GitHub",
"publisher": {
***@***.***": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]
|
This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
Suggestion
I think the inferred type for
err
incatch (err) { }
should beunknown
, which it is, instead ofany
which is unsafe and highly discouraged.unknown
is safer and provides better semantics; I really don't understand why this is not the default for tsc.🔍 Search Terms
catch exception type inference infer unknown any
✅ Viability Checklist
My suggestion meets these guidelines:
⭐ Suggestion
Infer the type for
err
incatch (err) { }
asunknown
📃 Motivating Example
This is valid Typescript 4.2.3 code as shown here
💻 Use Cases
What do you want to use this for?
What shortcomings exist with current approaches?
What workarounds are you using in the meantime?
The text was updated successfully, but these errors were encountered: