export function debounce < T extends unknown [ ] > ( fn , delay ) { let timeout ; return function debounced ( ... args ) { const execFetch = ( ) => { timeout = undefined ; fn ( ... args ) ; } ; if ( timeout !== undefined ) clearTimeout ( timeout ) ; if ( delay < 0 ) { execFetch ( ) ; timeout = undefined ; } else { timeout = setTimeout ( execFetch , delay ) ; } } ; }