/** * @ignore */ export function debounce unknown>(func: T, wait = 166) { let timeout: ReturnType; function debounced(this: unknown, ...args: Parameters) { const later = () => { func.apply(this, args); }; clearTimeout(timeout); timeout = setTimeout(later, wait); } debounced.clear = () => { clearTimeout(timeout); }; return debounced as T & Cancelable; } /** * @ignore */ export interface Cancelable { clear(): void; }