@future-widget-lab/safe-ops
Version:
A set of helper functions for performing operations safely, preventing runtime errors from disrupting your application.
14 lines (13 loc) • 335 B
TypeScript
/**
* @description
* Use this helper to safely invoke an async function and catch any errors that occur.
*/
export declare const attemptAsync: <TData, TError = Error>(fn: () => Promise<TData>) => Promise<{
ok: boolean;
result: Awaited<TData>;
error: null;
} | {
ok: boolean;
result: null;
error: TError;
}>;