Skip to content

Instantly share code, notes, and snippets.

@chrishow
Created March 13, 2025 11:16
Show Gist options
  • Save chrishow/5cc150c666e90908490366a2e725adcd to your computer and use it in GitHub Desktop.
Save chrishow/5cc150c666e90908490366a2e725adcd to your computer and use it in GitHub Desktop.
Tiny debounce in Typescript
// Tiny debounce
interface DebounceFunction {
(callback: (...args: any[]) => void, frequency?: number, timer?: number | null): (...args: any[]) => void;
}
export const debounce: DebounceFunction = (callback, frequency = 250, timer: number | null = null) => {
return (...args: any[]) => (
clearTimeout(timer!), (timer = setTimeout(function () {
callback();
}, frequency, ...args))
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment