export type Result = Ok | Err; /** * Utility metho to create an `Ok` result from a `value` * * @param value - `value` used to crete the `Result` * @returns an instance of a `Ok` `Result` inferring its type */ export declare const ok: (value: TValue) => Ok; /** * Utility method to create an `Error` result from an `error` * * @param err - `error` used to crete the `Result` * @returns an instance of an `Error` `Result` inferring its type */ export declare const err: (err: TError) => Err; export declare class Ok { readonly value: TValue; constructor(value: TValue); /** * Check if a `Result` is an `Err` inferring its type. `!isErr()` should be used before accessing the `value` * * @returns `false` as the `Resul` is `OK` */ isErr(): this is Err; /** * Runs the `handler` method an return the same an unaltered copy of the `Result`. It could be used to log an * output when the result is `Ok` without breaking the flow * * @param handler - method to be run when the result is `Ok` * @returns a copy of the same `Result` */ doOnOk(handler: (value: TValue) => void): Result; /** * A safe mode to throw the `error` of the `Result` */ valueOrBug(): TValue; /** * Throws an abort error if the result doesn't represent a value. */ valueOrAbort(): TValue; /** * Maps the value to another one with a different type. It leaves the `Error` type unaltered * * @param mapper - The mapper method to apply an `OK` value * @returns a new result with the new mapped value */ map(mapper: (value: TValue) => TMappedValue): Result; /** * Maps the error type to another one. It leaves the `Ok` type and value unaltered * * @param _mapper - This mapper method is not used for an `Ok` value * @returns a new result with the new mapped error type and an value */ mapError(_mapper: (error: TError) => TMappedError): Result; } export declare class Err { readonly error: TError; constructor(error: TError); /** * Check if a `Result` is an `Err` inferring its type. `!isErr()` should be used before accessing the `value` * * @returns `false` as the `Resul` is `OK` */ isErr(): this is Err; /** * Return an unaltered copy of the `Error` without doing anything. * * @param _handler - This handler method is not used for an `Error` * @returns a copy of the same `Error` */ doOnOk(_handler: (value: TValue) => void): Result; /** * A safe mode to throw the `error` of the `Result` */ valueOrBug(): TValue; /** * Throws an abort error if the result doesn't represent a value. */ valueOrAbort(): TValue; /** * Maps the value type to another one. It leaves the `Error` unaltered * * @param _mapper - This mapper method is not used for an `Error` value * @returns a new result with the new value type and an unaltered error */ map(_mapper: (valueOrBug: TValue) => TMappedValue): Result; /** * Maps the error to another one with a different type. It leaves the value type unaltered * * @param mapper - The mapper method to apply an `Error` value * @returns a new result with the new mapped error */ mapError(mapper: (error: TError) => TMappedError): Result; }