Skip to content

unwrap ​

The unwrap() function extracts the inner value of a WrappedValue. If the input is not wrapped, it is returned as is.

Interactive example ​

Syntax ​

typescript
type Unwrap<
	GenericAnyValue extends unknown
> = GenericAnyValue extends WrappedValue<infer inferredValue>
		? inferredValue
		: GenericAnyValue;

function unwrap<
	GenericInput extends AnyValue,
	GenericAnyValue extends AnyValue | WrappedValue<GenericInput>
>(
	anyValue: GenericAnyValue
): Unwrap<GenericAnyValue>;

Parameters ​

  • anyValue : Wrapped or non-wrapped value to unpack.

Return value ​

The inner value if the input was wrapped, otherwise the input value.

See also ​

Released under the MIT license.