Skip to content

Yield delegation fails for class instance of async iterable  #15137

@OliverJAsh

Description

@OliverJAsh

TS 2.3 RC

{
    const iterable: Iterable<number> = {
        [Symbol.iterator]: () => 1 as any as Iterator<number>
    }

    const asyncIterable: AsyncIterable<number> = {
        [Symbol.asyncIterator]: () => 1 as any as AsyncIterator<number>
    }

    class AsyncIterable2 implements AsyncIterable<number> {
        [Symbol.asyncIterator] = () => 1 as any as AsyncIterator<number>
    }

    const asyncIterable2 = new AsyncIterable2()

    const gen = async function*(): AsyncIterator<number> {
        yield 0;
        yield* [1]
        yield* iterable
        yield* asyncIterable
        yield* asyncIterable2 // Error: The type returned by the 'next()' method of an iterator must have a 'value' property.
    }

    gen()
}

I would expect asyncIterable2 to work, but it errors. See code comment above.

I'm using type assertions because the values don't matter so much, just trying to prove the types should fit together.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptDuplicateAn existing issue was already created

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions