2627. Debounce ¶ TypeScript 1 2 3 4 5 6 7 8 9type F = (...args: number[]) => void; function debounce(fn: F, t: number): F { let timeout: ReturnType<typeof setTimeout> | undefined; return function (...args) { clearTimeout(timeout); timeout = setTimeout(() => fn(...args), t); }; }