Closed rbarros-daitan closed 4 years ago
I believe the problem occurs when expression evaluates to union type where Promise is one option such as undefined | Promise<void>
. booleanExpression && promiseExpression
is one example.
Another example:
function test(): Promise<void> | undefined {
return undefined;
}
_test(); // no-floating-promises should fail, but it does not
a && b
whereb
is aPromise
Yes, this is intentional. That is technically not a "floating" promise, as the promise is being used (as silly as that sounds). See #3983; this should be better documented per #4117.
test(): Promise<void> | undefined
Seems like that's a tricky bug with no-floating-promises
. If a type union that contains a Promise
is returned, then the code flow path that contains the Promise must handle it... which sounds pretty hard to do for TSLint. Marking this as accepting a bug fix, but if it ends up being hundreds of lines of code, it might not be worth it.
TSLint is deprecated and no longer accepting pull requests other than security fixes. See #4534. ☠️ We recommend you instead use typescript-eslint to lint your TypeScript code with ESLint. ✅
👋 It was a pleasure open sourcing with you!
🤖 Beep boop! 👉 TSLint is deprecated 👈 (#4534) and you should switch to typescript-eslint! 🤖
🔒 This issue is being locked to prevent further unnecessary discussions. Thank you! 👋
Bug Report
TypeScript code being linted
It seems tslint does not see a problem because when exists a "a && b" syntax (with allow-fast-null-checks in no-unused-expression rule enabled). It looks like an independent rule. "a && b" can be allowed, but if the b expression is a promise, no promise not handled is launched.
Actual behavior
Tests are ok with expression "a && b" when b is promise not handled.
Expected behavior
The "no-floating-promises" rule should fail.