UNPKG

return-style

Version:

Non-intrusively convert the result of any function or promise to the user's desired style.

11 lines (10 loc) 247 B
export function getErrorResult<E = Error, T = unknown>( fn: () => T ): [error: undefined, result: T] | [error: E, result: undefined] { try { const result = fn() return [void 0, result] } catch (e: any) { return [e, void 0] } }