declare const __result__: unique symbol; export type Ok = { type: "Ok"; value: T; readonly isOk: true; readonly isErr: false; readonly [__result__]: true; }; export type Err = { type: "Err"; error: E; readonly isOk: false; readonly isErr: true; readonly [__result__]: true; }; /** Discriminated union: mutually exclusive Ok or Err */ export type Result = (Ok | Err) & ResultMethods; /** Methods available on a Result */ export interface ResultMethods { /** * Unwraps the value, throwing for Err. * @example maybeFail().expect("must succeed") */ expect(msg?: string): T; /** * Returns an unwrap chain that throws if no else is provided. * Use `.else(valueOrFn)` to supply a fallback for Err. * - If `Ok`, `.else(...)` returns the inner value and ignores fallback. * - If `Err`, `.else(...)` returns the fallback; if a function, it receives the error. */ unwrap(): { /** * Fallback value or function to recover from Err. * If a function is provided, it is called with the Err's error. * Returns the unwrapped value (Ok) or the provided fallback (Err). */ else(fallback: T | ((error: any) => T)): T; }; /** * Transforms the inner value if `Ok`, returns same `Err` if `Err`. * - If fn returns `undefined`, returns original Result (no new allocation). * - If fn throws, returns `Err(message)`. * - Supports async functions, returning `Promise>`. * @example * Ok(5).andThen(x => x * 2); // Ok(10) * Err("fail").andThen(x => x * 2); // Err("fail") * Ok(5).andThen(x => undefined); // Ok(5) - original * await Ok(5).andThen(async x => x); // Ok(5) */ andThen(fn: (value: T) => U | Promise): Result | Promise>; } /** * Creates a new, successful result. * @param value Value of the result * @example * const a = Ok("hello"); * typeof a; // Ok<"hello"> */ export declare function Ok(value: T): Ok & ResultMethods; /** * Creates a new, failed result with a string error message. * @param error Error message (must be a string) * @example * const a = Err("something went wrong"); * typeof a; // Err */ export declare function Err(error: string): Err & ResultMethods; export {};