import { UnhandledError } from './error.js'; /** * Type guard: checks if value is an Error. * After this check, TypeScript narrows the type to the error types in the union. * * @example * const result = await fetchUser(id) * if (isError(result)) { * // result is narrowed to the error type * return result * } * // result is narrowed to User * console.log(result.name) */ export declare function isError(value: V): value is Extract; /** * Type guard: checks if value is NOT an Error. * Inverse of isError for convenience. * * @example * const result = await fetchUser(id) * if (isOk(result)) { * console.log(result.name) // result is User * } */ export declare function isOk(value: V): value is Exclude; /** * Execute a sync function and return either the value or an error. * * @overload Simple form - wraps exceptions in UnhandledError * @example * const result = tryFn(() => JSON.parse(input)) * // result: UnhandledError | unknown * * @overload With custom catch - you control the error type * @example * const result = tryFn({ * try: () => JSON.parse(input), * catch: (e) => new ParseError({ cause: e }) * }) * // result: ParseError | unknown */ export declare function tryFn(fn: () => T): UnhandledError | T; export declare function tryFn(opts: { try: () => T; catch: (e: Error) => E; }): E | T; /** * Execute an async function and return either the value or an error. * * @deprecated Use `.catch()` directly on the promise instead. It's simpler, * composes naturally with async/await, and TypeScript infers the union * automatically. `tryAsync` adds an unnecessary wrapper around what `.catch()` * already does. * * @example Migration from tryAsync to .catch() * ```ts * // Before (tryAsync): * const result = await tryAsync({ * try: () => fetch(url), * catch: (e) => new NetworkError({ url, cause: e }), * }) * * // After (.catch): * const result = await fetch(url) * .catch((e) => new NetworkError({ url, cause: e })) * ``` * * @example Simple form migration * ```ts * // Before: * const result = await tryAsync(() => fetch(url).then(r => r.json())) * * // After: * const result = await fetch(url).then(r => r.json()) * .catch((e) => new NetworkError({ url, cause: e })) * ``` */ export declare function tryAsync(fn: () => Promise): Promise; export declare function tryAsync(opts: { try: () => Promise; catch: (e: Error) => E | Promise; }): Promise; //# sourceMappingURL=core.d.ts.map