[Typescript 4.9] Auto-Accessors in Classes
Typescript 4.9 supports an upcoming feature: Auto-accessors:
class Person {
accessor name: string
constructor(name: string) {
this.name = name
}
}
Under the covers, it is a "getter' and "setter" with an unreachable private property.
class Person {
#__name: string
constructor(name: string) {
this.name = name
}
get name() {
return this.#__name
}
set name(name: string) {
this.#__name = name
}
}