Skip to content

class initialization fails when #private static field is present together with computed method name #44113

Closed
@0kku

Description

@0kku

Bug Report

🔎 Search Terms

static ES private fields, static private members, computed class method name, class instantiation fails

🕗 Version & Regression Information

4.3.0-beta

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about static class members
  • I was unable to test this on prior versions because static ES private fields weren't added until 4.3

⏯ Playground Link

Playground link with relevant code

💻 Code

class Foo {
    static #qux = 42;
    ["bar"] () {}
}

new Foo;

🙁 Actual behavior

A runtime error ReferenceError: Cannot access 'Foo' before initialization when using target: "es2021" when trying to instantiate a class that contains both a static ES #private field and a method that has a computed method name. Compiled code runs fine without runtime errors when using target: "ESNEXT" (no downleveling).

🙂 Expected behavior

Code runs without errors.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions