Skip to content

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

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

Activity

  1. hikarino-my commented on Mar 16, 2020

    @hikarino-my
    Contributor

    I've created a PR that should fix this issue.
    Could someone check for it please?
    #37424

  2. kitsonk commented on Jul 15, 2020

    @kitsonk
    ContributorAuthor

    Daniel Rosenwasser (@DanielRosenwasser) Ryan Cavanaugh (@RyanCavanaugh) any chance of some action on this. PR has been open since 4+ months with no review.

    For us, the side effect of this is that when we "bundle" modules in Deno, and use SystemJS as the target, the emitter doesn't realise the module requires TLA and so it breaks the bundle.

  3. dandv commented on Jan 15, 2021

    @dandv
    Contributor

    Adding another search term, the error code: TS1103.

  4. hikarino-my commented on Jan 15, 2021

    @hikarino-my
    Contributor

    I thought this was already merged an year ago.🥱

  5. locked as resolved and limited conversation to collaborators on Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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