param func param wait param immediate returns export const debounce = < T extends ( ... args ) => unknown > ( func , wait , immediate = false ) : T => { let timeout ; return function ( ... args ) { const context = this ; const later = ( ) => { timeout = null ; if ( ! immediate ) { func . apply ( context , args ) ; } } ; const callNow = immediate && ! timeout ; clearTimeout ( timeout ) ; timeout = setTimeout ( later , wait ) ; if ( callNow ) { func . apply ( context , args ) ; } } ; } ;