Class Result<T>

This module contains the 'Result' class, which represents wrapper for a value that can be either a success or an error.

The 'Result' class provides methods to unwrap the value, expect a value or isOk or isErr to check if the result is successful.

Type Parameters

  • T

Hierarchy

  • Result

Constructors

Properties

Methods

Constructors

  • Initializes a Result object.

    Type Parameters

    • T

    Parameters

    • value: T

      expected value for passing case

    • error: null | string = null

      error message for non-passing case

    Returns Result<T>

Properties

error: null | string = null

error message for non-passing case

Methods

  • Returns the value if the Result is successful. Throws an assertion error if not.

    Parameters

    • msg: string

      The message to be displayed if the Result has failed.

    Returns NonNullable<T>

    The value if the Result is successful.

    Throws

    If there is an error in the result, it throws an assertion error with the given message.

  • Determines if the Result represents a failed outcome.

    Returns bool

    true if the Result is not okay, false otherwise.

  • Determines if the Result represents a successful outcome.

    Returns bool

    true if the Result is okay, false otherwise.

  • Get the value of the Result.

    Returns NonNullable<T>

    The value of the Result if successful.

    Remarks

    This method panics if the Result is an error.

    Throws

    If there is an error in the result, it throws an assertion error with the given message.

Generated using TypeDoc