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.

    Returns

    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.

    Parameters

    • msg: string

      The message to be displayed if the Result has failed.

    Returns NonNullable<T>

  • Determines if the Result represents a failed outcome.

    Returns

    true if the Result is not okay, false otherwise.

    Returns bool

  • Determines if the Result represents a successful outcome.

    Returns

    true if the Result is okay, false otherwise.

    Returns bool

  • Get the value of the Result.

    Remarks

    This method panics if the Result is an error.

    Returns

    The value of the Result if successful.

    Throws

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

    Returns NonNullable<T>

Generated using TypeDoc