要使用 function 而不是 箭头函数
typescript
interface MethodDecorator<T> {
(
target: Object,
propertyKey: string | symbol,
descriptor: TypedPropertyDescriptor<T>
): TypedPropertyDescriptor<T> | void;
}
type TMethodDecorator = MethodDecorator<any>;
const matchImport: TMethodDecorator = (target, propertyKey, descriptor) => {
const callback = descriptor.value;
descriptor.value = function (...args: any[]) {
console.log("decorator", this);
return callback.call(this, ...args);
};
};