gogoend / blog

blogs, ideas, etc.
MIT License
9 stars 2 forks source link

装饰器 #77

Open gogoend opened 1 year ago

gogoend commented 1 year ago

类装饰器

/**
 * @param { TFunction } target 被装饰的类
 */
type ClassDecorator = <TFunction extends Function>(target: TFunction) => TFunction | void;

属性装饰器

/**
 * @param { TFunction } target 被装饰的类
 * @param { string | symbol } propertyKey 属性的key
 */
type PropertyDecorator = (target: Object, propertyKey: string | symbol) => void;

方法装饰器

/**
 * @param { TFunction } target 被装饰的方法
 * @param { string | symbol } propertyKey 方法的key
 * @param { TypedPropertyDescriptor<T> } descriptor 属性描述符
 */
type MethodDecorator = <T>(target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T> | void;

参数装饰器

/**
 * @param { TFunction } target 被装饰的方法
 * @param { string | symbol } propertyKey 方法的key - 若被装饰的参数位于constructor,此处key将为`undefined`
 * @param { number } parameterIndex 参数所在索引
 */
type ParameterDecorator = (target: Object, propertyKey: string | symbol, parameterIndex: number) => void;