Interface IWeakOption<B, T>

interface IWeakOption<B, T> {
    has(base: B): boolean;
    unwrapForce(base: B): T;
    unwrapOrDefault(base: B, altValue: T): T;
    unwrapOrElse(base: B, f: ((...vals: any) => T)): T;
    unwrapOrUndefined(base: B): undefined | T;
}

Type Parameters

  • B extends object
  • T

Implemented by

Methods

  • Checks if a value exists for the given base object.

    Parameters

    • base: B

      The base object used as a key

    Returns boolean

    True if the value exists, false otherwise

  • Forcefully unwraps the value, throwing an error if it doesn't exist.

    Parameters

    • base: B

      The base object used as a key

    Returns T

    The stored value

    When the value doesn't exist

  • Unwraps the value or returns a default value if it doesn't exist.

    Parameters

    • base: B

      The base object used as a key

    • altValue: T

      The alternative value to return if the value doesn't exist

    Returns T

    The stored value or the alternative value

  • Unwraps the value or executes a function to get an alternative value.

    Parameters

    • base: B

      The base object used as a key

    • f: ((...vals: any) => T)

      Function to execute if the value doesn't exist

        • (...vals): T
        • Parameters

          • Rest...vals: any

          Returns T

    Returns T

    The stored value or the result of the function

  • Unwraps the value or returns undefined if it doesn't exist.

    Parameters

    • base: B

      The base object used as a key

    Returns undefined | T

    The stored value or undefined