export const withTimeout = < T > ( e , ms ? ) : Promise < T > => new Promise ( ( resolve , reject ) => { const timout = setTimeout ( ( ) => { reject ( 'Promise timed out' ) ; } , ms ) ; e . then ( ( result ) => { resolve ( result ) ; clearTimeout ( timout ) ; } ) . catch ( reject ) ; } ) ;