export type OuterPromise < T = any > = Promise < T > & { resolve : ( value ? : any ) => void ; reject : ( error : Error | string ) => void ; done : boolean ; timeout : number | undefined ; } ; param timeout export const outerPromise = ( timeout ? ) => { const temp = { done : false , timeout } ; let t ; const promise = new Promise ( ( a , b ) => { temp . resolve = ( value ) => { if ( t ) clearTimeout ( t ) ; temp . done = true ; a ( value ) ; } ; temp . reject = ( error ) => { if ( t ) clearTimeout ( t ) ; temp . done = true ; b ( error ) ; } ; } ) ; temp . then = ( ... args ) => promise . then ( ... args ) ; temp . catch = ( ... args ) => promise . catch ( ... args ) ; temp . finally = ( ... args ) => promise . finally ( ... args ) ; const res = < OuterPromise > temp ; if ( timeout ) t = setTimeout ( ( ) => res . reject ( new Error ( "Timeout" ) ) , timeout ) ; return res ; } ;