镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Incorrect emit of defining class expression with static property inside loop #8578

Description

@yuit

As jeffreymorlan points out in the PR #8551, below code is emited incorrectly.

Compiler options: --target es5, --target es6

const arr: {y(): number}[] = [];
for (let i = 0; i < 3; i++) {
    arr.push(class C {
        static x = i;
        static y = () => C.x * 2;
    });
}
arr.forEach(C => console.log(C.y()));

Activity

  1. added this to the TypeScript 2.0 milestone on May 12, 2016
  2. self-assigned this
    on May 12, 2016
  3. modified the milestones: TypeScript 2.1, on Sep 29, 2016
  4. RyanCavanaugh commented on Mar 11, 2019

    @RyanCavanaugh
    Member

    Verified

  5. jakebailey commented on Jul 5, 2023

    @jakebailey
    Member

    Just looking at old bugs; this one was fixed in #43197 and contains associated tests for class declarations in loops.

  6. 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

Assignees

No one assigned

    Labels

    BugA bug in TypeScript

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions