Merged in chore/typing-debounce (pull request #1668)
chore: debounce function is now typed to accommodate typed parameters in a callback Approved-by: Simon.Emanuelsson
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
export function debounce(func: Function, delay = 300) {
|
||||
export function debounce<Params extends any[]>(
|
||||
func: (...args: Params) => any,
|
||||
delay = 300
|
||||
) {
|
||||
let debounceTimer: ReturnType<typeof setTimeout>
|
||||
return function () {
|
||||
// @ts-expect-error this in TypeScript
|
||||
|
||||
return function <U>(this: U, ...args: Parameters<typeof func>) {
|
||||
const context = this
|
||||
const args = arguments
|
||||
clearTimeout(debounceTimer)
|
||||
debounceTimer = setTimeout(() => func.apply(context, args), delay)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user