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
}
}
标签:Typescript,string,Auto,4.9,Classes,Accessors,name From: https://www.cnblogs.com/Answer1215/p/16938576.html