type UnwrapResult | any> = T extends Result ? U : T; type UnwrapError> = T extends Result ? E : never; export type AsyncResult = Promise>; export type TCollectResult = Result<{ [key in keyof T]: T[key] extends Result ? A : T[key]; }, { [key in keyof T]: T[key] extends Result ? B : never; }[keyof { [key in keyof T]: T[key] extends Result ? B : never; }]>; export declare class Result { private _type; private _data; private _error; private constructor(); /** * Produces a Failing Result instance * @param error * @returns */ static fail(error: E): Result; /** * Produces a Ok Result Instance * @param data * @returns */ static ok(data: S): Result; /** * Collects a array of Results into a Result of Array, * or outputs the first Failing Result. * Ignores non-result types from the generated array * @param results * @returns */ static collect(results: Array>): Result; /** * Collects a object os key: Result into a Result, and * E being the first Failing result * If a object key contains something that's not a Result, the value is kept * in the final object Ok * @param obj * @returns */ static collectObject | any>>(resultsObject: T): Result<{ [K in keyof T]: UnwrapResult; }, UnwrapError>; static isResult(result: any | Result): result is Result; /** * Returns True is Result is Ok * @returns boolean */ isOk(): boolean; /** * Returns true is Result is Fail * @returns boolean */ isFail(): boolean; /** * Unwraps the Ok value of a Result. If the Result is Fail, an error is thrown. * @returns The success value of the Result. * @throws {NoOkValueError} Will throw an error if the Result is Fail. */ unwrap(): S; /** * Unwraps the Fail value of a Result. If the Result is Ok, an error is thrown. * @returns The error value of the Result. * @throws {NoFailValueError} Will throw an error if the Result is Ok. */ unwrapFail(): E; /** * Applies a function into the Ok value of the result while propagating the Fail * @param transform * @returns */ map(transform: (data: S) => NewS): Result; /** * Applies a function into the Fail value of the result while propagating the Ok * @param transform * @returns */ mapFail(transform: (error: E) => NewE): Result; /** * Applies a function that returns a result into the Ok value of the result, if Failing, can return the original Fail or the new Fail * @param transform * @returns */ flatMap(transform: (data: S) => Result): Result; /** * Applies a function that returns a result into the Fail value of the result, if Ok, can return the original Ok or the new Ok * @param transform * @returns */ flatMapFail(transform: (error: E) => Result): Result; /** * Applies a async function into the Ok value of the result while propagating the Fail * Returns the Result as a Promise * @param transform * @returns */ asyncMap(transform: (data: S) => Promise): Promise>; /** * Applies a async function into the Fail value of the result while propagating the Ok * Returns the Result as a Promise * @param transform * @returns */ asyncMapFail(transform: (error: E) => Promise): Promise>; /** * Applies a async function that returns a result into the Ok value of the result, if Failing, can return the original Fail or the new Fail * Returns the Result as a Promise * @param transform * @returns */ asyncFlatMap(transform: (data: S) => Promise>): Promise>; /** * Applies a async function that returns a result into the Fail value of the result, if Ok, can return the original Ok or the new Ok * Returns the Result as a Promise * @param transform * @returns */ asyncFlatMapFail(transform: (error: E) => Promise>): Promise>; } export declare const Fail: typeof Result.fail; export declare const Ok: typeof Result.ok; export {};