When using a `StackReference`, how do you get the ...
# general
f
When using a
StackReference
, how do you get the output as an array? I tried this:
Copy code
let subnetIds = myStack.getOutput("subnetIds") as pulumi.Output<string[]>;
but Typescript fails with:
TS2740: Type 'Output<any>' is missing the following properties from type 'Input<string>[]': length, pop, push, concat, and 26 more..
. I'm fairly certain the type of
getOutput
is correct.
i
Guessing that is
pulumi.Output<pulumi.Output<string>[]>
helps to
import {Output} from '@pulumi/pulumi'
to shorten it up
oh yes, stack.getOutput returns
Output<any>
, I was thinking Input types
f
That results in a similar message:
Copy code
TS2740: Type 'Output<Output<string>[]>' is missing the following properties from type 'Input<string>[]': length, pop, push, concat, and 26 more.
i
that’s another one for @lemon-spoon-91807
f
Fairly certain the type is Output<string[]> from
getOutput
. If I do
Copy code
myStack.getOutput("subnetIds").apply(x => { console.log(x); return x;})
x
is printed as an array.
i
I think the
getOutput
return type is overly vague since it could be one of many. It could possibly be parameterized to allow a return type, like
getOutput<string[]>
to provide a better dev experience. As-is it is a cast either way to what you want to use.
👍 1
f
FWIW, I'm trying to create a vpc from the output:
Copy code
let subnetIds = myStack.getOutput("subnetIds") as pulumi.Output<string[]>;
const vpc = awsx.ec2.Vpc.fromExistingIds("infra-vpc", {
    vpcId: vpcId,
    publicSubnetIds: subnetIds,
});
and the error is on the
publicSubnetIds
line.
I can convert it to a
Output<Output<string>[]>
but
publicSubnetIds
doesn't like that either.
l
I would love to help you. And i will! But i'm oof for a few days.
However, let me say this: you should never have Outputs in other Outputs
because Outputs 'unwrap' their data
You can have
Input<Input<string>[]>
you could also have
Output<string[]>
do go from the former to the latter, you just call
pulumi.output(the_inputs)