TypeScript: view on playground
class A {
protected _name: string = ""
set name(name: string) {
this._name = name
}
get name() {
return this._name
}
}
class B extends A {
protected _name: string = ""
set name(name: string) {
this._name = name + "B"
}
}
In the compiled class B this will overwrite the definition of the set
AND get
:
Object.defineProperty(B.prototype, "name", {
set: function (name) {
this._name = name + "B";
},
enumerable: true,
configurable: true
});
The result is, that get name
does not work anymore on class B:
let b = new B()
b.name = "test"
console.log(b.name) // undefined
Is there a way to inherit the getter from class A?