Skip to content

Yield delegation inside for..await terminates iterable early #15143

Closed
@OliverJAsh

Description

@OliverJAsh

TS 2.3 RC

Given:

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

    const innerGen = async function* () {
        yield 10
        yield 20
    }
    const gen = async function* () {
        yield* innerGen()
        yield* innerGen()
    }

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

    main();
}

When ran with Node, I get:

❯ tsc && node ./target/AsyncIterable.js
10
20

I expected:

10
20
10
20

When delegating to an async iterable inside, TypeScript ends the outer async iterable when the delegated async iterable ends.

This is different from the behaviour of sync iterables, and not to spec (AFAIK).

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