@rustresult/result
Version:
Rust-like Result and ResultAsync for Javascript
47 lines (46 loc) • 1.7 kB
TypeScript
import type { Result } from './Result';
import type { ResultAsync } from './ResultAsync';
/**
* Creates a `ResultAsync` that contains the success value.
*
* Examples:
* ```ts
* const result1 = OkAsync(1);
* const result2 = OkAsync<number, string>(1);
* const result3: ResultAsync<number, string> = OkAsync(1);
* ```
*/
export declare function OkAsync<T, E = never>(value: T | Promise<T>): ResultAsync<T, E>;
/**
* Creates a `ResultAsync` that contains the error value.
*
* Examples:
* ```ts
* const result = ErrAsync('Some error message');
* ```
*/
export declare function ErrAsync<E>(error: E | Promise<E>): ResultAsync<never, E>;
/**
* Creates a `ResultAsync` that contains the error value.
*
* Examples:
* ```ts
* const result1 = ErrAsync<number, string>('Some error message');
* const result2: ResultAsync<number, string> = ErrAsync('Some error message');
* ```
*/
export declare function ErrAsync<T, E>(error: E | Promise<E>): ResultAsync<T, E>;
/**
* Creates a `ResultAsync` from a promiseable `Result`.
*
* Examples:
* ```ts
* const result1 = fromPromiseableResult<number, string>(Ok(1));
* const result2 = fromPromiseableResult<number, string>(Err('Some error message'));
* const result3 = fromPromiseableResult<number, string>(Promise.resolve(Ok(1)));
* const result4 = fromPromiseableResult<number, string>(Promise.resolve(Err('Some error message')));
* const result5 = fromPromiseableResult<number, string>(OkAsync(1));
* const result6 = fromPromiseableResult<number, string>(ErrAsync('Some error message'));
* ```
*/
export declare function fromPromiseableResult<T, E>(result: Result<T, E> | Promise<Result<T, E>> | ResultAsync<T, E>): ResultAsync<T, E>;