Skip to content

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

@clemyan

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

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScript

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions