-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Enhancement: [use-unknown-in-catch-callback-variable] Option to only check inline functions #9057
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
Comments
Note: a related idea came up in the rule proposal, see #7526 (comment) I personally don't have a strong opinion. Several points in favor and several points against spring to mind. We'll see what others say. |
yeah I'm personally -1 on this given that the usecase of specifically passing an "external" function that accepts Now-a-days I think most 3rd-party things are going to accept
Assuming that you have that compiler option turned on or that you have that rule turned on. |
FWIW the only pain I had with adopting this rule is when I'm passing error-tracking utilities. redisClient.connect().catch(winston.error);
redisClient.connect().catch(console.error);
redisClient.connect().catch(Sentry.captureException); NONE OF THESE work. So, I'm a big fan. If you are not implementing this function there's not much you can do anyway. |
Having thought more thoroughly about this, I am +1 to the request as well. Passed in handlers will never have implicitly |
I don't feel strongly enough about this to want to push back against multiple 👍s. I'll defer to the rest of the team's majority. 🙂 |
Kirk and I both hold the thought that this is fine: function handler(x: any) {
// ...
}
Promise.reject().catch(handler); It's still |
3 months later and this request has received 2 community reactions. There are documented workarounds:
And this is not a super common usecase given the low volume of community engagement. |
Coming over from #10435: I've experienced the pain of this in production and now believe it is worth it to implement.
This is annoying, unnecessary, and makes the rule overly pedantic
Also inconvenient. And not always doable, e.g. with the common I'm now in favor. |
Before You File a Proposal Please Confirm You Have Done The Following...
My proposal is suitable for this project
Link to the rule's documentation
https://typescript-eslint.io/rules/use-unknown-in-catch-callback-variable/
Description
I propose an option to only check on inline functions, i.e.
.catch((foo) => bar)
and not.catch(baz)
. Ifbaz
acceptsany
, it's either from an external library or will be flagged by--noImplicitAny
/no-explicit-any
.Use case: I have a few instances of
.catch(console.error)
in my codebase to log errors without throwing.console.error
is typed as(...data: any[]): void
, and as such this rule triggers an error.Fail
Pass
Additional Info
No response
The text was updated successfully, but these errors were encountered: