export type PromiseCreator < T = any > = ( ... args : any [ ] ) => Promise < T > ; /**
 * Discard the previous return values, only keep the last return values
 */ function takeLatest < FuncType extends PromiseCreator > ( promiseCreator ) { let index = 0 ; return ( ( ... args ) => { index += 1 ; const promise = promiseCreator ( ... args ) ; function latest ( func , reqIndex ) { return ( ... innerArgs ) : void => { if ( reqIndex === index ) { func ( ... innerArgs ) ; } } ; } return new Promise ( ( resolve , reject ) => { promise . then ( latest ( resolve , index ) , latest ( reject , index ) ) ; } ) ; } ) as FuncType ; } export default takeLatest ;