/** * Success result containing a value */ export type Success = { res: T; err: undefined; }; /** * Failure result containing an error */ export type Failure = { res: undefined; err: E; }; /** * Result type - discriminated union of Success or Failure */ export type Result = Success | Failure; /** * Async result type - Promise that resolves to a Result */ export type AsyncResult = Promise>; /** * Union type representing either a synchronous Result or an asynchronous AsyncResult */ export type AnyResult = Result | AsyncResult; /** * Factory function that receives an error and returns an Error instance */ export type ErrorFactory = (error: E) => Error; /** * Optional parameter for ensure function - either a custom error message string or a factory function */ export type EnsureErrorOption = string | ErrorFactory | undefined; /** * Creates a successful result without a value * @returns A Success result with undefined value */ export declare function ok(): Success; /** * Creates a successful result * @param value - The success value * @returns A Success result */ export declare function ok(value: T): Success; /** * Creates a failed result with a custom error type * @param error - The error instance * @returns A Failure result with the custom error type */ export declare function err(error: E): Failure; /** * Creates a failed result with a string message (becomes Error) * @param message - The error message string * @returns A Failure result with Error type */ export declare function err(message: string): Failure; /** * Unwraps a synchronous Result, throwing an error if the result is a failure * Cannot be used with Result - use type-level protection to prevent undefined returns * @param result - The Result to unwrap (must not be Result) * @returns The value if successful (never undefined) * @throws Error if the result is a failure */ export declare function ensure(result: Result): Exclude; /** * Unwraps a synchronous Result with custom error handling, throwing an error if the result is a failure * Cannot be used with Result - use type-level protection to prevent undefined returns * @param result - The Result to unwrap (must not be Result) * @param errorOption - Optional error message string or factory function that receives the error and returns an Error instance * @returns The value if successful (never undefined) * @throws Error if the result is a failure */ export declare function ensure(result: Result, errorOption: EnsureErrorOption): Exclude; /** * Unwraps an asynchronous AsyncResult, returning a Promise that resolves to the value or rejects if the result is a failure * Cannot be used with AsyncResult - use type-level protection to prevent undefined returns * @param result - The AsyncResult to unwrap (must not be AsyncResult) * @returns A Promise that resolves to the value if successful (never undefined) * @throws Error if the result is a failure */ export declare function ensure(result: AsyncResult): Promise>; /** * Unwraps an asynchronous AsyncResult with custom error handling, returning a Promise that resolves to the value or rejects if the result is a failure * Cannot be used with AsyncResult - use type-level protection to prevent undefined returns * @param result - The AsyncResult to unwrap (must not be AsyncResult) * @param errorOption - Optional error message string or factory function that receives the error and returns an Error instance * @returns A Promise that resolves to the value if successful (never undefined) * @throws Error if the result is a failure */ export declare function ensure(result: AsyncResult, errorOption: EnsureErrorOption): Promise>; /** * Unwraps a Result or AsyncResult, throwing an error if the result is a failure * Cannot be used with Result or AsyncResult - use type-level protection to prevent undefined returns * @param result - The Result or AsyncResult to unwrap (must not be Result or AsyncResult) * @returns The value (or Promise that resolves to the value) if successful (never undefined) * @throws Error if the result is a failure */ export declare function ensure(result: Result | AsyncResult): Exclude | Promise>; //# sourceMappingURL=result.d.ts.map