Type alias Unwrap<T>

Unwrap<T>: T extends Promise<infer U1>
    ? UnwrapSimple<U1>
    : T extends OutputInstance<infer U2>
        ? UnwrapSimple<U2>
        : UnwrapSimple<T>

The 'Unwrap' type allows us to express the operation of taking a type, with potentially deeply nested Promises and Outputs and to then get that same type with all the Promises and Outputs replaced with their wrapped type. Note that this Unwrapping is 'deep'. So if you had:

 `type X = { A: Promise<{ B: Output<{ c: Input<boolean> }> }> }`

Then Unwrap<X> would be equivalent to:

 `...    = { A: { B: { C: boolean } } }`

Unwrapping sees through Promises, Outputs, Arrays and Objects.

Note: due to TypeScript limitations there are some things that cannot be expressed. Specifically, if you had a Promise<Output<T>> then the Unwrap type would not be able to undo both of those wraps. In practice that should be ok. Values in an object graph should not wrap Outputs in Promises. Instead, any code that needs to work Outputs and also be async should either create the Output with the Promise (which will collapse into just an Output). Or, it should start with an Output and call [apply] on it, passing in an async function. This will also collapse and just produce an Output.

In other words, this should not be used as the shape of an object: { a: Promise<Output<...>> }. It should always either be { a: Promise<NonOutput> } or just { a: Output<...> }.

Type Parameters

  • T

Generated using TypeDoc