@duydang2311/attempt
Version:
Go-like error handling for JavaScript and TypeScript
31 lines (28 loc) • 1.22 kB
TypeScript
// Generated by dts-bundle-generator v9.5.1
declare const symbol: unique symbol;
export type Attempt<TData, TError> = {
readonly [symbol]: true;
readonly ok: true;
readonly failed: false;
readonly data: TData;
} | {
readonly [symbol]: true;
readonly ok: false;
readonly failed: true;
readonly error: TError;
};
export interface AttemptAsyncFn {
<TData, TError>(fn: () => Promise<Attempt<TData, TError>>): <TError2>(mapException?: (e: unknown) => TError2) => Promise<Attempt<TData, TError | TError2>>;
<TData>(fn: () => Promise<TData>): <TError>(mapException?: (e: unknown) => TError) => Promise<Attempt<TData, TError>>;
}
export declare const attemptSync: <TData>(fn: () => TData) => <TError>(mapException?: (e: unknown) => TError) => Attempt<TData, TError>;
export declare const attemptAsync: AttemptAsyncFn;
export declare const attemptOk: <T>(data: T) => Attempt<T, never>;
export declare const attemptFail: <T>(error: T) => Attempt<never, T>;
export declare const attempt: {
sync: <TData>(fn: () => TData) => <TError>(mapException?: (e: unknown) => TError) => Attempt<TData, TError>;
async: AttemptAsyncFn;
ok: <T>(data: T) => Attempt<T, never>;
fail: <T>(error: T) => Attempt<never, T>;
};
export {};