UNPKG

ts-data-forge

Version:

[![npm version](https://img.shields.io/npm/v/ts-data-forge.svg)](https://www.npmjs.com/package/ts-data-forge) [![npm downloads](https://img.shields.io/npm/dm/ts-data-forge.svg)](https://www.npmjs.com/package/ts-data-forge) [![License](https://img.shields.

30 lines 1.09 kB
import { type Unwrap } from './types.mjs'; /** * Unwraps an `Optional`, returning the contained value or throwing an error * with the provided message. * * @example * * ```ts * 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'); * ``` * * @template O The `UnknownOptional` type to unwrap. * @param optional The `Optional` to unwrap. * @param message The error message to throw if the `Optional` is * `None`. * @returns The contained value if `Some`. * @throws Error with the provided message if the `Optional` is * `None`. */ export declare function expectToBe<O extends UnknownOptional>(optional: O, message: string): Unwrap<O>; export declare function expectToBe<S>(message: string): (optional: Optional<S>) => S; //# sourceMappingURL=optional-expect-to-be.d.mts.map