Skip to content

abstract modifier cannot be used with private a identifierΒ #60617

@lilnasy

Description

@lilnasy

πŸ”Ž 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions