-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Enhancement: [no-floating-promises] Provide a built-in SafePromise type #10666
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
Now answering as a team member: I don't think this would be good, and here's a long explanation why... We in typescript-eslint do not decide userland best practices or conventions. It would be inappropriate for us decide these things: we're not the universal experts of everything and are certainly not qualified to represent the vastness of the JS/TS world's various frameworks+libraries+tools. Rather, we attempt to represent the best practices and conventions that already exist in userland. We do our best to drop our personal biases -e.g. I abhor allowing The distinction is important because I don't want people to come away from these discussions thinking that we in typescript-eslint made a decision for the community, or that the aforementioned workarounds in frameworks are purely because of typescript-eslint. We just happen to be the only mainstream linter right now with a fully working All that is why we have not been in favor of adding a branded type like
Putting it all together: IMO 👎 we shouldn't provide a |
It's been >3 months since we added the Closing out as out of scope for this project. If anybody has significant new information for the issue of a built-in "SafePromise" type or similar, such as community consensus on a single type, please do post back in a new issue. We'd be happy to take a look. For folks who want a no-floating-promises rule that respects a SafePromise type, you're welcome to use the docs in https://typescript-eslint.io/developers to build a rule/plugin that has that. You can always fork the rule from tseslint. Cheers! 💖 |
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/no-floating-promises
Description
Coming over from discussions such as #5844, #7008, #8404, reduxjs/redux-toolkit#4101, fastify/fastify#5498, #9869: one known user pain with
@typescript-eslint/no-floating-promises
is around frameworks/libraries that intentionally make "fire-and-forget" Promises. If a function's calls don't need anawait
by design, it's inconvenient to have the rule report on them by default.The
allowForKnownSafeCalls
andallowForKnownSafePromises
rule options make this better, but also require user linter configuration. For example, Redux Toolkit added aSafePromise
type perallowForKnownSafePromises
. Users can allowlist that type in their ESLint configs. This works but is inconvenient. Most users don't want to deeply hand-edit their ESLint configs for frameworks-specific nuances like this.We are occasionally asked: can typescript-eslint provide its own
SafePromise
type that frameworks can use, and thatno-floating-promises
would allowlist/ignore by default?Fail
Pass
Additional Info
I don't see an issue like this in our issue tracker, but know it's been suggested in at least some DMs to me. So I'm surfacing it here on behalf of users.
💖
The text was updated successfully, but these errors were encountered: