The process of wrapping a class with a decorator causes superclasses to be unable to access that classes\' properties. Why?
I have some code that:
A solution using ES2015 Proxy to override the constructor:
function wrap(target: any) {
return new Proxy(target, {
construct(clz, args) {
console.log(`Constructing ${target.name}`);
return Reflect.construct(clz, args);
}
});
}
@wrap
class Base {
prop: number = 5;
}
class Extended extends Base {
constructor() {
super()
}
}
var a = new Extended()
console.log(new Extended().prop);
You can also run this on StackBlitz