Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
kitsonk opened this issue Mar 15, 2020 · 4 comments · Fixed by #37424
Closed

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

kitsonk opened this issue Mar 15, 2020 · 4 comments · Fixed by #37424
Labels
Bug A bug in TypeScript Help Wanted You can do this
Milestone

Comments

@kitsonk
Copy link
Contributor

kitsonk commented Mar 15, 2020

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

@hikarino-my
Copy link
Contributor

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

@kitsonk
Copy link
Contributor Author

kitsonk commented Jul 15, 2020

@DanielRosenwasser @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.

@dandv
Copy link
Contributor

dandv commented Jan 15, 2021

Adding another search term, the error code: TS1103.

@hikarino-my
Copy link
Contributor

hikarino-my commented Jan 15, 2021

I thought this was already merged an year ago.🥱

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Help Wanted You can do this
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants