export interface Box < T > { error : Error | null ; result : T ; } param fn export function box < T > ( fn ) { if ( typeof fn !== "function" ) { throw new TypeError ( "fn provided to box must be a function" ) ; } return async ( ... args ) : Promise < Box < T > > => { try { return { error : null , result : await fn ( ... args ) } ; } catch ( error ) { return { error , result : null } ; } } ; } ;