type FnType = (...args: T) => unknown; export default function debounce( fn: FnType, wait = 1000 ): (...args: Parameters>) => void { let timeout: number | undefined; return function (this: unknown, ...args): void { const laterCall = (): unknown => fn.apply(this, args); window.clearTimeout(timeout); timeout = window.setTimeout(laterCall, wait); }; }