Skip to content

typeof doesn't work with #private fields - identifier expected #54337

Closed
@kalleguld

Description

@kalleguld

Bug Report

🔎 Search Terms

typeof, private field, class field, identifier expected

🕗 Version & Regression Information

  • This changed between versions 4.3.5 and 4.4.4 (prior to 4.4.4, typeof didn't work at all).
  • I have tested in 5.0.4 (bug is there)
  • I have tested in 5.1.0 Beta (bug is there).

⏯ Playground Link

Playground link with relevant code

💻 Code

class Foo {
  private privateVal : number = 42;

  testFunc() {
    let d : typeof this.privateVal;  //this works
    d = this.privateVal + 1;
    return d;
  }
}

class Bar {
  #privateVal : number = 42;

  testFunc() {
    let d : typeof this.#privateVal;  //this fails: identifier expected
    d = this.#privateVal + 1;
    return d;
  }
}

🙁 Actual behavior

Code should have compiled. A private field / class field should be treated as an identifier.

🙂 Expected behavior

I'd expect typeof this.#privateVal; to be number.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions