Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

abstract modifier cannot be used with private a identifier #60617

Open
lilnasy opened this issue Nov 26, 2024 · 0 comments
Open

abstract modifier cannot be used with private a identifier #60617

lilnasy opened this issue Nov 26, 2024 · 0 comments
Labels
Bug A bug in TypeScript Help Wanted You can do this
Milestone

Comments

@lilnasy
Copy link

lilnasy commented Nov 26, 2024

πŸ”Ž Search Terms

abstract, private fields, classes

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about Classes

⏯ Playground Link

https://www.typescriptlang.org/play/?ssl=17&ssc=22&pln=1&pc=1#code/IYIwzgLgTsDGEAJYBthjAgggg3gKAQVEhngQGIAPALgQDsBXAWxAFMoCFOBzViADQAUASlydCUPgyh0EEABYBLMADoqnAL55OkYBEWwEAIQQBeJKnTGErShFZ0AJhmz5ChWAHs6JBvE9QImLu7mAMAA7sIuLuCspqlGYIAKwxWoRaWnhePojASXSsAO5YKkbZ3mCeyKwqyJ7cgsAqvAIiwkA

πŸ’» Code

abstract class A {
  abstract #x: number
  
  getX() {
    return this.#x
  }

  static B = class B extends A {
    constructor() {
      super()
      this.#x = 5
    }
  }
}

const a = new A.B
console.log(a.getX())

This code works as you would expect at runtime (chrome devtools screenshot), since nested static classes can access the same private fields as their containing class.

πŸ™ Actual behavior

TypeScript errors on line 2 with this message:

'abstract' modifier cannot be used with a private identifier.(18019)

... requiring a ts-expect-error directive.

πŸ™‚ Expected behavior

The abstract keyword is allowed.

Additional information about the issue

No response

@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript Help Wanted You can do this labels Nov 26, 2024
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Help Wanted You can do this
Projects
None yet
Development

No branches or pull requests

2 participants