export function debounce void>( func: T, wait: number ): (...args: Parameters) => void { let timeout: ReturnType | undefined; return function (this: any, ...args: Parameters) { const context = this; const later = () => { timeout = undefined; func.apply(context, args); }; if (timeout !== undefined) { clearTimeout(timeout); } timeout = setTimeout(later, wait); }; }