Skip to content

Top Level "for await" not supported, but should be #37402

Closed
@kitsonk

Description

@kitsonk

TypeScript Version: 3.8.3

Search Terms:

top level for await

Code

const arr = [ Promise.resolve() ];

for await (const item of arr) {
  item;
}

export {};

Expected behavior:

To compile without issue.

Actual behavior:

A 'for-await-of' statement is only allowed within an async function or async generator. (1103)

In the Stage 3 proposal, tc39/proposal-top-level-await#133 was specifically added to address that for await is valid. Therefore the TypeScript implementation is incomplete. While it was implemented in V8 separately, V8 now supports it (as well as potentially other engines).

Playground Link: link

Related Issues: #25988

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions