export type Deferred < T > = PromiseLike < T > & { resolve : ( value : T | PromiseLike < T > ) => void ; reject : ( reason ? : any ) => void ; promise : Promise < T > ; } ; export const deferred = < T = void > ( ) : Deferred < T > => { let resolveFn ; let rejectFn ; const promise = new Promise < T > ( ( res , rej ) => { resolveFn = res ; rejectFn = rej ; } ) ; return { resolve : ( value ) => resolveFn ( value ) , reject : ( reason ? ) => rejectFn ( reason ) , then : promise . then . bind ( promise ) , promise , } ; } ;