Skip to content

Playground doesn't support async generators. #15

Closed

Description

I put the following code into https://www.typescriptlang.org/play/

async function f(): Promise<number> {
    return 1;
}

async function* g(): AsyncIterator<number> {
    yield 1;
    await f();
    return 2;
}

The compiler reports two errors on the async function *g() line.

  • Cannot find global type 'AsyncIterableIterator'
  • Cannot find name 'AsyncIterator'

Is that expected?

Activity

  1. mhegazy commented on Apr 2, 2018

    @mhegazy

    The playground does not have a way to set compiler options, e.g. target, or --lib. it is similar to microsoft/TypeScript#18209.
    The long term solution is to make it configurable. as a short term fix i will add the latest lib file.

  2. justjake commented on Apr 12, 2019

    @justjake

    Bump: it can't find AsyncIterableIterator:

    async function* generate() {
        yield 0
        yield 1
        yield 2
    }
    
    type Returned = ReturnType<typeof generate>
    

    reports Error: Cannot find global type AsyncIterableIterator'.

    https://www.typescriptlang.org/play/#src=async%20function*%20generate()%20%7B%0D%0A%20%20%20%20yield%200%0D%0A%20%20%20%20yield%201%0D%0A%20%20%20%20yield%202%0D%0A%7D%0D%0A%0D%0Atype%20Returned%20%3D%20ReturnType%3Ctypeof%20generate%3E

  3. saarw commented on Oct 22, 2019

    @saarw

    Also getting 'Cannot find name "AsyncGenerator"'

  4. orta commented on Mar 10, 2021

    @orta
    Contributor

    Setting the target to ESNext works with all these samples out of the box o the playground 👍🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

PlaygroundIssues that affect the PlaygroundPlayground ATAHoles in the current type acquisition

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions