curious if anyone has an elegant way of recursivel...
# typescript
e
curious if anyone has an elegant way of recursively resolving promises in a pulumi object? Currently I’m doing something like the following, but this isn’t aware of how deep the object goes.
Copy code
pulumi.output((chartResources).apply((v) => {
            for (const [k, x] of Object.entries(v)) {
                for (const [m, n] of Object.entries(x)) {
                    pulumi.output(n).apply((maybe) => 
                    console.log(JSON.stringify(maybe)))
o
That's interesting, I thought
pulumi.output(...).apply()
deeply resolved promises & outputs already.
Are you finding that they still have the Output/Promise type within the apply block?
e
yea 😞
the top level resolves, but the nested ones do not
o
Hmm, what if you did this?
Copy code
pulumi.output(chartResources.Apply(x => x)).Apply((v) => {
            for (const [k, x] of Object.entries(v)) {
                for (const [m, n] of Object.entries(x)) {
                    pulumi.output(n).apply((maybe) => 
                    console.log(JSON.stringify(maybe)))
The return value of
.apply()
uses "Unwrap<T>" to simplify types recursively
e
hmm, let me try, I’m open to anything at this point
o
Using the identity function with the first apply might allow you to simplify a deep type.
e
bummer, there are still unresolved nested objects! Curses!
o
That sounds like a bug - if you could produce a minimal example and file it on GitHub.com/Pulumi/Pulumi that would be appreciated! For any object x: Output<T> where T has nested outputs, promises, Pulumi.apply(x => x) should return Output<U> where U has all outputs and promises fields of T as plain values
e
aah, yea that would be ideal. Thanks! Our team will follow-up with a ticket & bug report