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:
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<...> }.
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:
Then
Unwrap<X>
would be equivalent to: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 callapply
on it, passing in anasync
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<...> }
.