ts-data-forge
    Preparing search index...
    • Converts an Optional to a nullable value.

      This function extracts the value from an Optional, returning undefined for empty Optionals. This is useful when interfacing with APIs or systems that expect nullable values rather than Optional types.

      Note: This returns undefined (not null) for consistency with JavaScript's undefined semantics and TypeScript's optional properties.

      Type Parameters

      Parameters

      • optional: O

        The Optional to convert.

      Returns Unwrap<O> | undefined

      The contained value if Some, otherwise undefined.

      const someNumber = Optional.some(42);
      const noneNumber = Optional.none as Optional<number>;

      assert(Optional.toNullable(someNumber) === 42);
      assert(Optional.toNullable(noneNumber) === undefined);