'Constructor of subclass' prototype is enumerable in TypeScript
Here is my code:
class Animal {
constructor(public name: string){}
}
class Cat extends Animal {
constructor(public name: string) {
super(name);
}
}
It outputs the following code:
var __extends = this.__extends || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
__.prototype = b.prototype;
d.prototype = new __();
};
var Animal = (function () {
function Animal(name) {
this.name = name;
}
return Animal;
})();
var Cat = (function (_super) {
__extends(Cat, _super);
function Cat(name) {
_super.call(this, name);
this.name = name;
}
return Cat;
})(Animal);
And as you can see from this demo, the constructor gets enumerated as a key.
The property constructor of the Class Cat's prototype should be non-enumerable, but the method __extends has changed this. How can I repair this?
I know the following code can achieve this, but I want a way that TypeScript natively supports!
Object.defineProperty(Cat.prototype, 'constructor', {
enumerable: false
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
