param fn returns export function switchMap < T extends ( ... args : any [ ] ) => Promise < any > > ( fn ) { let id = 0 ; let last = 0 ; let cache ; return async function ( ... args ) { const temp = id ; id ++ ; const res = await fn ( ... args ) ; if ( temp < last ) { return cache ; } cache = res ; last = temp ; return res ; } as T ; }