ts-data-forge
    Preparing search index...
    • Unwraps an Optional, returning the contained value. Throws an error if the Optional is None.

      This is a safer alternative to direct value access when you know the Optional should contain a value. Use this method when an empty Optional represents a programming error or unexpected condition.

      Type Parameters

      • O extends UnknownOptional

        The UnknownOptional type to unwrap.

      Parameters

      • optional: O

        The Optional to unwrap.

      Returns Unwrap<O>

      The contained value if Some.

      const present = Optional.some('available');

      assert.isTrue(Optional.unwrapThrow(present) === 'available');

      assert.throws(
      () => Optional.unwrapThrow(Optional.none),
      /has failed because it is `None`/u,
      );

      Error with message "unwrapThrow() has failed because it is None" if the Optional is None.