Skip to content

Unable to use top-level for-await loops with module preserve #59030

Closed

Description

@clemyan

🔎 Search Terms

"top-level await", "for-await", "preserve", "ts1432"

🕗 Version & Regression Information

  • This changed between versions 5.3 and 5.4 (for module: preserve)

⏯ Playground Link

https://www.typescriptlang.org/play/?target=99&module=200&ts=5.6.0-dev.20240625#code/GYewTgBAhg7lCWAXCAKAxiAdgZ2QDwhGAgG0BdASggG8BfCAegYgFEwxwAoWBZABQ4BbeNgCmAOjCjsIADYA3USgoBuRswDyAaU6dReAA7hkdFUA

💻 Code

for await (const x of []) {} // Error
await Promise.resolve(); // OK

export {};

🙁 Actual behavior

The code errors with ts1432 under module: preserve (regardless of target)

🙂 Expected behavior

The code compiles without error under module: preserve and target: ESNext

Additional information about the issue

No response

Activity

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

Metadata

Metadata

Labels

Bug

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions