while using stack reference, and also using apply...
# typescript
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}`);
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
in the future:
Copy code
primaryNodePool.apply(pnp => console.log(`nodepool: ${pnp}`));
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
Your code and mine are the same 🙂 The logging is inside the apply. That's the way it has to be.
Thank you for helping out,