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 getResultError<E = Error, T = unknown>( fn: () => T ): [result: T, error: undefined] | [result: undefined, error: E] { try { const result = fn() return [result, void 0] } catch (e: any) { return [void 0, e] } }