Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
Closed as not planned
Closed as not planned
Description
Before You File a Bug Report Please Confirm You Have Done The Following...
- I have tried restarting my IDE and the issue persists.
- I have updated to the latest version of the packages.
- I havesearched for related issues and found none that matched my issue.
- I haveread the FAQ and my problem is not listed.
Playground Link
Repro Code
// contrived exampleasyncfunction*eachLine(_stream:ReadableStream<Uint8Array>):AsyncGenerator<string,void,undefined>{yield"implementation omitted"}exportasyncfunctionlogLines(stream?:ReadableStream<Uint8Array>):Promise<void>{constlines=stream ?eachLine(stream) :["some","defaults"];forawait(constlineoflines){console.log(line)}}
ESLint Config
module.exports={"rules":{"@typescript-eslint/await-thenable":"warn"}}
tsconfig
{"compilerOptions": {"strictNullChecks":true }}
Expected Result
If a value isAsyncIterable | Iterable
, you need afor await...of
loop to iterate over it, so the linter doesn't complain.
Actual Result
await-thenable
reports
Unexpected `for await...of` of a value that is not async iterable. 8:3 - 8:34> Convert to an ordinary `for...of` loop.
If you apply the suggestion, which in the example is
for(constlineoflines){
then the linter is satisfied but the code is broken and the compiler knows it:
2488: Type 'AsyncGenerator<string, void, undefined> | never[]' must have a '[Symbol.iterator]()' method that returns an iterator. 8:22 - 8:27
Additional Info
It'sfine to usefor await...of
to iterate over a sync iterable. It makes sense not to use this construct if youknow that you have a sync iterable, but if you may have either an async iterable or a sync one, then you need it.