type CallbackFunc = (...args: T) => void export function debounce( func: CallbackFunc, wait: number, ): (...args: T) => void { let timeoutId: ReturnType | undefined return (...args: T) => { const later = () => { clearTimeout(timeoutId) func(...args) } clearTimeout(timeoutId) timeoutId = setTimeout(later, wait) } }