/** * @ignore */ export function debounce any>(func: T, wait = 166) { let timeout: ReturnType; function debounced(...args: Parameters) { const later = () => { // @ts-ignore 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; }