Skip to content

Async generator function does not flatten yielded promises #15205

@OliverJAsh

Description

@OliverJAsh

TS 2.3 RC

declare const console: any;
{
    (Symbol as any).asyncIterator = Symbol.asyncIterator || "__@@asyncIterator__";

    const gen = async function* () {
        yield Promise.resolve(10)
        yield Promise.resolve(20)
    }

    const main = async () => {
        for await (const y of gen()) {
            console.log(y)
        }
    }

    main();
}

This outputs:

❯ tsc && node ./target/AsyncIterable.js
Promise { 10 }
Promise { 20 }

I expected it to output (promises are flattened):

10
20

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions