我想创建一个装饰器,如果需要,它会覆盖一些变量。就像是
const Decorator = <T extends { new (...args: any[]): any }>(target: T) => {
return class extends target {
field = 1;
field2 = 2;
};
};
但是对于一个类应该只有field,对于其他类应该只有field2,其中一些应该两者兼而有之。
我试过了,但它不起作用
const Decorator = <T extends { new (...args: any[]): any }>(target: T) => {
if (...) {
target.prototype.field = 1;
}
if (...) {
target.prototype.field2 = 2;
}
return class extends target {};
};