Class Err<E>

Represents the failure outcome of an operation with an error.

Type Parameters

  • E extends string | Error

    The type of the error value.

Constructors

Properties

Methods

Constructors

Properties

error: E

Methods

  • Extract the value or plain error from a Result.

    Type Parameters

    • T

      The type of the success value.

    Returns {
        error: E;
        value?: T;
    }

    • An object with the value or error property set.
    • error: E
    • Optional value?: T
  • Maps the error value to a new Result.

    Type Parameters

    • F extends string | Error

      The type of the error value of the new Result.

    Parameters

    • mapper: ((error) => Result<never, F>)

      A function to transform the error value.

    Returns Result<never, F>

    • A new Result with the transformed error value.
  • Retrieves the value or throws an error if the result is an Err.

    Type Parameters

    • T

    Returns T

    • The success value.

    Throws

    The error value if the result is an Err.

  • Maps the error value to a new error value.

    Type Parameters

    • F extends string | Error

      The type of the new error value.

    Parameters

    • mapper: ((error) => F)

      A function to transform the error value.

        • (error): F
        • Parameters

          • error: E

          Returns F

    Returns Result<never, F>

    • A new Result with the transformed error value.
  • Retrieves the error value or throws an error if the result is an Ok.

    Returns E

    • The error value.

    Throws

    The success value if the result is an Ok.

  • Creates an Err result with the specified error value.

    Type Parameters

    • E extends string | Error

      The type of the error value.

    Parameters

    • error: E

      The error value.

    Returns Err<E>

    • An Err result.

Generated using TypeDoc