@health-samurai/aidbox-client
    Preparing search index...

    Type Alias Result<T, E>

    Result: Ok<T> | Err<E>

    A classic Result type that can either be Ok or Err.

    Result wraps a value under the value field, and provides convenience methods for checking if Result is Ok or Err:

    const answer: Result<number, never> = Ok(42);

    answer.isOk(); // => true
    answer.isErr(); // => false

    If the function returns a compatible Result type, instead of unwrapping the result, and wrapping it back, map and mapErr methods can be used:

    function someFunctionA(x: number): Result<number, string> {
    if (0 === x % 2)
    return Err("number was even");
    return Ok(x);
    }

    function someFunctionB(num: number): Result<number, string> {
    return someFunctionA(num).map((x) => x + 1);
    }

    Type Parameters

    • T
    • E