export function throttle any>( func: T, limit: number, ): T { let lastFunc: ReturnType; let lastRan: number; return ((...args) => { if (!lastRan) { func(...args); lastRan = Date.now(); } else { clearTimeout(lastFunc); lastFunc = setTimeout(() => { if (Date.now() - lastRan >= limit) { func(...args); lastRan = Date.now(); } }, limit - (Date.now() - lastRan)); } }) as T; }