Skip to content

Down-level destructuring in for..in statement #3715

Closed as not planned
Closed as not planned

Description

@rbuckton

We report an error for the following code, :

for (var {toString} in { a: 1 }) { // error TS2491: The left-hand side of a 'for...in' statement cannot be a destructuring pattern.
   console.log(toString);
}

We also emit the following incorrect javascript:

for (var toString = (void 0).toString in { a: 1 }) {
    console.log(toString);
}

We should instead emit:

for (var _a in { a: 1 }) {
    var toString = _a.toString;
    console.log(toString);
}

While it is unlikely this will be very useful, this is another of the ES6 compatibility tests on the kangax compatibility table that we could consider addressing as it seems a small enough change.

Activity

  1. 1 remaining item

  2. modified the milestones: TypeScript 2.1, on Sep 29, 2016
  3. RyanCavanaugh commented on Feb 23, 2024

    @RyanCavanaugh
    Member

    The PR seems fine but maybe for simplicity let's just say it's still an error in scenarios where it would need to be downleveled? That way we're not ballooning the ES5 transform with something that ~no one will ever use.

  4. RyanCavanaugh commented on Aug 18, 2026

    @RyanCavanaugh
    Member

    This is moot due to ES5 deprecation

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 TypeScriptDomain: JS EmitThe issue relates to the emission of JavaScriptES6Relates to the ES6 Spec

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions