Skip to content

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

Closed

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.

Activity

  1. MartinJohns commented on May 21, 2023

    @MartinJohns
    Contributor

    Duplicate of #47595.

  2. fatcerberus commented on May 21, 2023

    @fatcerberus

    It appears this was fixed but later reverted because it caused a disruptive breaking change and requires architectural changes for a proper fix

  3. typescript-bot commented on May 24, 2023

    @typescript-bot
    Contributor

    This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

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

    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