Skip to content

Instantly share code, notes, and snippets.

@PatrykBuniX
Last active January 29, 2022 20:41
Show Gist options
  • Save PatrykBuniX/cfbe02014469053d7a3680cead84604e to your computer and use it in GitHub Desktop.
Save PatrykBuniX/cfbe02014469053d7a3680cead84604e to your computer and use it in GitHub Desktop.
Implementation of debounce function in TypeScript
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