ts-data-forge
    Preparing search index...
    • Unwraps an Optional, returning the contained value or throwing an error with the provided message.

      Type Parameters

      • O extends UnknownOptional

        The UnknownOptional type to unwrap.

      Parameters

      • optional: O

        The Optional to unwrap.

      • message: string

        The error message to throw if the Optional is None.

      Returns Unwrap<O>

      The contained value if Some.

      const optionalValue = Optional.some('data');

      assert.isTrue(Optional.expectToBe(optionalValue, 'value expected') === 'data');

      const expectValue = Optional.expectToBe<string>('missing optional');

      assert.throws(() => expectValue(Optional.none), /missing optional/u);

      assert.isTrue(expectValue(Optional.some('present')) === 'present');

      Error with the provided message if the Optional is None.

    • Unwraps an Optional, returning the contained value or throwing an error with the provided message.

      Type Parameters

      • S

      Parameters

      • message: string

        The error message to throw if the Optional is None.

      Returns (optional: Optional<S>) => S

      The contained value if Some.

      const optionalValue = Optional.some('data');

      assert.isTrue(Optional.expectToBe(optionalValue, 'value expected') === 'data');

      const expectValue = Optional.expectToBe<string>('missing optional');

      assert.throws(() => expectValue(Optional.none), /missing optional/u);

      assert.isTrue(expectValue(Optional.some('present')) === 'present');

      Error with the provided message if the Optional is None.