Currently working with Angular 17, I have a straightforward decorator that wraps the target with Proxy and a basic Angular component:
function proxyDecorator(target: any) {
return new Proxy(target, {
construct(target: any, argArray: any[], newTarget: Function): object {
console.log(`${target.name} proxy constructor`);
return Reflect.construct(target, argArray, newTarget);
}
});
}
@proxyDecorator
@Component({
selector: 'app-simple',
template: 'x'
})
export class SimpleComponent {
constructor() {
console.log('SimpleComponent constructor');
}
}
The issue arises where the console.log
within the proxyDecorator
is not being executed. This was functioning correctly in an app using Angular version 14. Interestingly, if I manually create an instance of the Component like so:
const simpleComponent = new SimpleComponent();
then the trap functions as intended. Any suggestions on how to address this?