Kit
Type aliases

UnwrappedOption

UnwrappedOption<T, U> = T extends Some<infer TValue> ? UnwrappedOption<TValue, U> : T extends None ? U : T extends UnUnwrappables ? T : T extends object ? { [key in keyof T]: UnwrappedOption<T[key], U> } : T extends infer TItem[] ? UnwrappedOption<TItem, U>[] : T

A type that recursively unwraps nested Option types.

This type resolves all nested Option values, ensuring that deeply wrapped values are properly extracted.

  • If T is an Option, it resolves to the contained value.
  • If T is a known primitive or immutable type, it remains unchanged.
  • If T is an object or array, it recursively unwraps any options found.

The fallback type U (default: null) is used in place of None values.

Type Parameters

Type ParameterDefault typeDescription
T-The type to be unwrapped.
UnullThe fallback type for None values (defaults to null).

Examples

Resolving nested Option types.

UnwrappedOption<Some<Some<string>>>; // string
UnwrappedOption<None>;               // null

Resolving options inside objects and arrays.

UnwrappedOption<{ a: Some<number>; b: None }>; // { a: number; b: null }
UnwrappedOption<[Some<number>, None]>;         // [number, null]

See

unwrapOptionRecursively

On this page