https://pulumi.com logo
#general
Title
# general
a

able-artist-91005

12/06/2023, 4:15 AM
How does one assign a stack output to an
Output<string>
variable? The docs show this example:
const ip: Output<string> = infra.getOutput("privateIp");
But I get a compilation error when I try something similar, since we can't assign Output<any> to Output<string>.
Copy code
TSError: ⨯ Unable to compile TypeScript:
    index.ts(28,9): error TS2322: Type 'Output<any>' is not assignable to type 'Output<string>'.
      Type 'OutputInstance<any>' is not assignable to type 'Output<string>'.
        Property 'length' is missing in type 'OutputInstance<any>' but required in type 'LiftedObject<String, NonFunctionPropertyNames<String>>'.
What's the correct solution here? Thanks
g

green-stone-37839

12/06/2023, 4:23 AM
getOutput("someKey")
return type is
pulumi.Output<any>
not
pulumi.Output<string>
. You could leave the variable untyped
const ip = ...
or also use an apply statement to provide the string type.
getOutput("someKey").apply(s => <string>s);
a

able-artist-91005

12/06/2023, 4:24 AM
So this is indeed a documentation bug?
g

green-stone-37839

12/06/2023, 4:25 AM
By the looks of it, yeah.
a

able-artist-91005

12/06/2023, 4:25 AM
thx for confirming
s

salmon-account-74572

12/06/2023, 4:58 PM
I’ve filed https://github.com/pulumi/docs/issues/10342 to fix the documentation issue noted here.