-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Enhancement: [await-thenable] should check that for-await
loop is used on an async iterable
#8858
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
This sounds a lot more like the promise aggregators rule (#8094) where you also want to check "some" or "all" of them are thenable... Which is why again I'm unhappy with that being a separate rule, because people would naturally expect await-thenable to work on things that get implicitly awaited too! |
@Josh-Cena +1 |
Note that there is also another completely redundant check to prohibit awaiting thenables in return-await: typescript-eslint/packages/eslint-plugin/src/rules/return-await.ts Lines 195 to 223 in fde4427
await-thenable: typescript-eslint/packages/eslint-plugin/src/rules/await-thenable.ts Lines 37 to 64 in fde4427
I guess that's a separate issue though. |
for-await
loopfor-await
loop
Just realized this request isn't about whether the loop is over However, note that if you have an
We can not add an option unless people complain loudly about it. We should add the reasoning above to the docs. |
for-await
loopfor-await
loop is used on an async iterable
Slightly awkward is the rule naming. We are not checking for thenables here (and even renaming it to |
Ah, yeah, I didn't even think about that implication of the example. Meant to signal that the array was not
Yep, wholeheartedly agree! |
Well, yes, and it is a quite bad name even for the current usage, and I think that's worthy of a separate discussion. As it is, the rule really is dont-await-non-thenables. I'd argue that an AsyncIterable is something whose |
Before You File a Bug Report Please Confirm You Have Done The Following...
Playground Link
https://typescript-eslint.io/play/#ts=5.4.3&showAST=es&fileType=.tsx&code=GYewTgBAhg7lCWAXCAKAxiAdgZ2diIwEA2gOSYikA0EpiAFgKaZQBGANo9tbU2I6QC6ASggBvAL4AoRgA8ADuGRiIEoA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6AQwHd3K78ALRE3YAjJOiiJo0APbRI4MAF8QSoA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false
Repro Code
ESLint Config
tsconfig
Expected Result
I expect that the first line should flag due to
for await
being used on something that does not have aSymbol.asyncIterator
.Actual Result
No error.
Additional Info
Note that it's unambiguous IMO that the example given should flag. However, I, personally, would also like for the rule to flag on misused for-await-of, where the iterable is a synchronous iterator over promises. That should be written as an ordinary for loop. It's only a true async iterable that should be allowed to be iterated over in a for-await-of loop.
Refresher on for-await-of: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of
The text was updated successfully, but these errors were encountered: