-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[no-floating-promises] feature: does-not-throw annotation #3192
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
Assessing comments is not something that we can do for a few reasons. The rule does not assess that the method So augmenting the rule to also assess not only that the promise came from This change would be very computationally expensive to implement, as it would need to inspect more and more types. Types are lazily computed, which means more types = more time. Additionally doing cross file source-code interrogation like this is expensive. Why not just use async/await? async function runWithString(provider: StringProvider) {
const s = await provider.string(); // no error here:
// - the success case is handled
// - the error case will throw
console.log('ready: ' + s);
} |
Thanks for your detailed explanation, it all makes sense!
In the cases where it is ok to block the control flow in the method with await it is the best option, but there things where we don't want the main control flow to be blocked on that, i.e. we know that the promise will resolve at some point in the future and we want to chain an action to it but we also want to proceed with logic in the current method not waiting for that, here is an one example and another one. This can always be solved by adding function runWithString(provider: StringProvider) {
provider.string().then(s => console.log('ready: ' + s), e => {}); // no error here:
} This is just about the convenience of using the rule. The idea of method annotation popped up in a discussion of the trade-offs between the amount of noise introduced by the |
no-floating-promises
rule currently supports to ways to suppress error: adding .catch to the promise and prependingvoid
to the expression. In many cases it's known that returned Promise never throws and having to prepend all call sites withvoid
just to suppress lint errors is tedious and impacts code readability. Rather than polluting all call sites with such annotations it'd be nice to have a marker on the async method/field telling lint that it never throws. Something like this:The text was updated successfully, but these errors were encountered: