Class Ok<T>

Represents the successful outcome of an operation with a value.

Type Parameters

  • T

    The type of the success value.

Constructors

Properties

Methods

Constructors

Properties

value: T

Methods

  • Extract the value or plain error from a Result.

    Type Parameters

    • E extends string | Error

      The type of the error value (must be string or instance of Error).

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

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

    Type Parameters

    • U

      The type of the success value of the new Result.

    Parameters

    • mapper: ((value) => Result<U, never>)

      A function to transform the success value.

    Returns Result<U, never>

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

    Returns T

    • The success value.

    Throws

    The error value if the result is an Err.

  • Maps the success value to a new value.

    Type Parameters

    • U

      The type of the new value.

    Parameters

    • mapper: ((value) => U)

      A function to transform the success value.

        • (value): U
        • Parameters

          • value: T

          Returns U

    Returns Result<U, never>

    • A new Result with the transformed value.
  • Creates an Ok result with the specified value.

    Type Parameters

    • T

      The type of the success value.

    Parameters

    • value: T

      The success value.

    Returns Ok<T>

    • An Ok result.

Generated using TypeDoc