Skip to content

Instantly share code, notes, and snippets.

@amitasaurus
Created May 4, 2024 02:56
Show Gist options
  • Save amitasaurus/e4c275199d2f1d4be2b5a56a8c4a223e to your computer and use it in GitHub Desktop.
Save amitasaurus/e4c275199d2f1d4be2b5a56a8c4a223e to your computer and use it in GitHub Desktop.
implementation of debounce in TypeScript
function debounce(
func: (...args: any[]) => any,
delay: number
): (...args: any[]) => void {
let timeoutId: ReturnType<typeof setTimeout> | null;
return function debouncedFunction(...args: any[]): void {
clearTimeout(timeoutId!);
timeoutId = setTimeout(() => {
func(...args);
}, delay);
};
}
export default debounce;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment