-
-
Save PatrykBuniX/cfbe02014469053d7a3680cead84604e to your computer and use it in GitHub Desktop.
Implementation of debounce function in TypeScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function debounce<T extends (...args: any[]) => any>( | |
func: T, | |
delay: number | |
) { | |
let debouncedTimeoutId: ReturnType<typeof setTimeout>; | |
return function (...args: Parameters<T>) { | |
clearTimeout(debouncedTimeoutId); | |
debouncedTimeoutId = setTimeout(func.bind(null, ...args), delay); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment