while using stack reference, and also using apply...
# typescript
s
while using stack reference, and also using apply getting the error `output<string> is not assignable to type string”, here is my code for the same
Copy code
const stack = pulumi.getStack();
const nodePoolStackRef = new pulumi.StackReference(`${org}/${orgName}/${stack}`);
let stackOutput = pulumi.interpolate`${nodePoolStackRef.getOutput("clusterNodePool")}`; 

const primaryNodePool = stackOutput.apply(v => v.toString());
console.log(`nodepool: ${primaryNodePool}`);
l
The 3rd line is a no-op, you can simply do
const stackOutput = nodePoolStackRef.getOutput("clusterNodePool");
The 4th line is a no-op, you can simply do
const primaryNodePool = stackOutput;
. The last line is trying to convert an Output<string> (which isn't available at run time, it's a future value) to a string. You can't do this. Instead, you call
console.log()
in the future:
Copy code
primaryNodePool.apply(pnp => console.log(`nodepool: ${pnp}`));
s
I did try the above, the future value or callback gives a similar unable to convert Output, the only way it works is below which isn’t ideal
Copy code
const nodePoolOut = stackOutput.apply(primaryNodePool => {
   console.log(`nodepool: ${primaryNodePool}`);
   -- rest of code is added here ---
return {
  some exported values
}
});
l
Your code and mine are the same 🙂 The logging is inside the apply. That's the way it has to be.
s
Thank you for helping out,