Skip to content

Allow annotations inside the head of a for...in statement #25605

Closed
@todor2810

Description

@todor2810

Unlike element in for (let element of iterable) {} and error in try {} catch (error) {} where element and error are determined at run-time, key in for (let key in object) {} is already known to be a string at compile-time.

I propose we accept an annotation for key. In other words, the following syntax should be valid:

for (let key: string in object) {}

Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript / JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. new expression-level syntax)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions