/** * @description simple debounce function */ export function debounce any>( func: T, wait: number, immediate: boolean = false, ): T { let timeout: any; return function anonymous(this: any, ...args: any[]) { const later = () => { timeout = null; if (!immediate) func.apply(this, args); }; const callNow = immediate && !timeout; clearTimeout(timeout); timeout = setTimeout(later, wait); if (callNow) func.apply(this, args); } as T; }