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