/** * Represent the successful case of a {@link TryCatch} tuple. * * @typeParam R - The type of the result. */ type Ok = [result: R, err: null]; /** * Represent the error case of a {@link TryCatch} tuple. */ type Err = [result: unknown, err: ThrownError]; /** * TryCatch represents the return value of the {@link $trycatch} utility. It is * composed of a tuple where the first element is the resulting value and the * second element is the caught error. The result element will be typed as * "unknown" until the absence of an error is asserted in the control flow, * Type narrowing will then unveil the actual type of the result. This ensures * that the presence of a value is always tied to the absence of an error, and * vice versa. The caught error is always encapsulated in an {@link ThrownError} * object and is available in the "cause" property. * * @typeParam R - The return type of the task. */ type TryCatch = Ok | Err; /** * Wraps a synchronous task in a try-catch block and returns the resulting * {@link TryCatch} tuple. * * @param task - A synchronous task. * @returns The resulting {@link TryCatch} tuple. */ export declare function $trycatch(task: () => never): TryCatch; /** * Wraps an asynchronous task in a try-catch block and returns a promise that * resolves with the resulting {@link TryCatch} tuple. * * @param task - An asynchronous task. * @returns The promise that resolves with the resulting {@link TryCatch} tuple. * @typeParam R - The return type of the task. */ export declare function $trycatch(task: () => Promise): Promise>; /** * Wraps a synchronous functional task in a try-catch block and returns its * {@link TryCatch}. * * @param task - A synchronous functional task. * @returns The task {@link TryCatch}. * @typeParam R - The return type of the task. */ export declare function $trycatch(task: () => R): TryCatch; /** * Chains a promise task with then/catch and return a promise that resolves * with the resulting {@link TryCatch} tuple. * * @param task - A promise task. * @returns The promise that resolves with the resulting {@link TryCatch} tuple. * @typeParam R - The return type of the task. */ export declare function $trycatch(task: Promise): Promise>; /** * Encapsulates a thrown value in an error object. */ export declare class ThrownError extends Error { /** * Creates a new error with the given cause. * * @param cause - The cause of the error. */ constructor(cause: unknown); } export {};