Evercatch - v0.10.0
    Preparing search index...

    Variable unwrapOrReadonly

    unwrapOr: <T, E extends unknown = Error>(result: Result<T, E>, fallback: T) => T

    See unwrapOr.

    Type declaration

      • <T, E extends unknown = Error>(result: Result<T, E>, fallback: T): T
      • Unwraps a Result, returning a fallback value if it contains an error.

        Type Parameters

        • T

          The type of the value.

        • E extends unknown = Error

          The type of the error.

        Parameters

        • result: Result<T, E>

          The Result to unwrap.

        • fallback: T

          The value to return when the result contains an error.

        Returns T

        The unwrapped value or the fallback.

        const value = unwrapOr(ok(42), 0);
        console.log(value); // 42
        const value = unwrapOr(err(new Error("Oops")), 0);
        console.log(value); // 0