Is it possible to properly extend a class constructor with decorators while maintaining the original class name and static attributes and methods?
Upon reading the handbook, there is a note that cautions about this scenario:
https://www.typescriptlang.org/docs/handbook/decorators.html#class-decorators
NOTE: If you choose to return a new constructor function,
make sure to preserve the original prototype.
The runtime logic for applying decorators does not handle this automatically.
One common issue when following the handbook's approach is losing the class name and static methods:
function my_decorator<T extends { new(...constr_args:any[]):any }>(constr_func:T){
return class extends constr_func {
constructor(...args: any[]){
// DO STUFF
super(...args);
// DO STUFF
}
}
}