@rustresult/result
Version:
Rust-like Result and ResultAsync for Javascript
51 lines (50 loc) • 1.85 kB
TypeScript
import type { Result } from './Result';
import type { ResultAsync } from './ResultAsync';
import type { Optional } from './types.internal';
/**
* DO NOT USE THIS CLASS. This is for internal use.
*/
export declare class RustlikeResult<T, E> implements Result<T, E> {
private readonly _type;
private readonly _value?;
private readonly _error?;
constructor(type: 'ok', value: T);
constructor(type: 'err', error: E);
/**
* Creates a `Result` that contains the success value.
*/
static Ok<T, E = never>(value: T): Result<T, E>;
/**
* Creates a `Result` that contains the error value.
*/
static Err<E, T = never>(error: E): Result<T, E>;
isOk(): this is Result<T, never>;
isOkAnd(fn: (value: T) => boolean): boolean;
isErr(): this is Result<never, E>;
isErrAnd(fn: (err: E) => boolean): boolean;
ok(): Optional<T>;
err(): Optional<E>;
map<U>(op: (value: T) => U): Result<U, E>;
mapOr<U>(fallback: U, map: (value: T) => U): U;
mapOrElse<U>(fallback: (err: E) => U, map: (value: T) => U): U;
mapErr<F>(op: (err: E) => F): Result<T, F>;
inspect(fn: (value: T) => void): this;
inspectErr(fn: (err: E) => void): this;
private _unwrapFailed;
expect(msg: string): T;
unwrap(): T;
expectErr(msg: string): E;
unwrapErr(): E;
unwrapOr(fallback: T): T;
unwrapOrElse(op: (err: E) => T): T;
unwrapUnchecked(): T;
unwrapErrUnchecked(): E;
and<U>(res: Result<U, E>): Result<U, E>;
andThen<U>(op: (value: T) => Result<U, E>): Result<U, E>;
or<F>(res: Result<T, F>): Result<T, F>;
orElse<F>(op: (err: E) => Result<T, F>): Result<T, F>;
transpose(): Optional<Result<T & NonNullable<unknown>, E>>;
private static _equal;
equal(other: Result<unknown, unknown>): boolean;
async(): ResultAsync<T, E>;
}