annotate_debounce_in_typescript #49
bowencool
announced in
Announcements
Replies: 1 comment
-
加餐后来在使用过程中,又遇到一个报错,再当做装饰器的时候: class A {
@debounce
public method() {}
}
这个问题一开始也懵逼,后来查资料才知道方法装饰器的参数跟类装饰器不太一样。这个确实是知识盲区,没啥好说的,看看文档,封装了一个: /**
* @description 方法装饰器工厂:去抖
* @example ``` js
* @Debounce(300)
* public method() {}
* ```
*/
export function Debounce(ms: number = 300) {
return function debounceDecorator(
target: any,
propertyKey: keyof typeof target,
descriptor: TypedPropertyDescriptor<(...args: any[]) => void>,
) {
const originFn = descriptor.value;
if (typeof originFn === 'function') {
const debouncedFn = debounce(originFn, ms);
descriptor.value = debouncedFn;
}
};
} 这里又留下了一个问题没有解决,就是原生的 MethodDecorator: |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
annotate_debounce_in_typescript
记一次在 Typescript 中给 debounce 写注解
https://blog.bowen.cool/zh/posts/annotate_debounce_in_typescript
Beta Was this translation helpful? Give feedback.
All reactions