/** * Result type implementation inspired by Rust's Result * Provides a type-safe way to handle success and error cases. * * Available methods: * - `isOk()` / `isErr()` - Check if operation succeeded or failed * - `unwrap()` - Get the value (throws if error) * - `unwrapOr(default)` - Get value or return default */ interface IResult { isOk(): this is Ok; isErr(): this is Err; unwrap(): T; unwrapOr(defaultValue: T): T; unwrapErr(): E; } declare class Ok implements IResult { readonly value: T; constructor(value: T); isOk(): this is Ok; isErr(): this is Err; unwrap(): T; unwrapOr(_defaultValue: T): T; unwrapErr(): E; } declare class Err implements IResult { readonly error: E; constructor(error: E); isOk(): this is Ok; isErr(): this is Err; unwrap(): T; unwrapOr(defaultValue: T): T; unwrapErr(): E; } type Result = Ok | Err; /** * Creates a successful Result containing the given value. */ declare function ok(value: T): Result; /** * Creates a failed Result containing the given error. */ declare function err(error: E): Result; /** * Wraps a function that might throw into a Result. */ declare function tryCatch(fn: () => T): Result; /** * Wraps an async function that might throw into a Promise. */ declare function tryCatchAsync(fn: () => Promise): Promise>; export { Ok, Err, Result, ok, err, tryCatch, tryCatchAsync };