function debounce void>(func: T, delay: number) { let timeoutId: ReturnType; return function (this: ThisParameterType, ...args: Parameters) { clearTimeout(timeoutId); timeoutId = setTimeout(() => { func.apply(this, args); }, delay); }; }