Hi, Apologies if answered before but how would I g...
# typescript
w
Hi, Apologies if answered before but how would I go about merging/concating two promise output instance arrays? i.e.
Copy code
const ids: Promise<pulumi.Output<string>[]>
const otherIds: Promise<pulumi.Output<string>[]>

ids.concat(otherIds)
I've tried with
then
and also
apply
like;
pulumi.output(ids).apply()
etc... To no avail. Any help would be greatly appreciated. 🙏
l
A useful "trick" here is to note that outputs lift or unwrap themselves automatically, so you can get rid of the Promise like this:
Copy code
const ids: Promise<pulumi.Output<string>[]>
const outputIds = pulumi.output(ids);
Unfortunately the strong type system means you can't unwrap at declaration time:
outputIds
is technically of type
pulumi.Output<Promise<pulumi.Output<string>[]>>
. But you can use it as if it was of type
pulumi.Output<string>[]
due to the unwrapping.
1
You can use the trick to concat the arrays thus:
Copy code
const ids: Promise<pulumi.Output<string>[]>
const otherIds: Promise<pulumi.Output<string>[]>

const concattedIds = pulumi.all([pulumi.output(ids), pulumi.output(otherIds)]);
1
You don't even need to use
apply
. If you followed the example in the docs for
all()
, you'd have this:
Copy code
const concattedIds = pulumi.all([pulumi.output(ids), pulumi.output(otherIds)]).apply(([x, y]) => x.concat(y));
But that's pretty much exactly what
pulumi.all()
does anyway, so you can skip that bit.
1
w
Morning @little-cartoon-10569, Thank you so much for the explanation. I was unawares of
pulumi.all
too. Your advice worked a treat 👍 🙏
I was also able to make progress on another component I'm developing
Copy code
const sourceStage: pulumi.Input<pulumi.Input<inputs.codepipeline.PipelineStage>[]> = [
            {
                name: 'Source',
                actions: [
                    {
                        name: 'Source',
                        category: 'Source',
                        owner: 'AWS',
                        provider: 'CodeStarSourceConnection',
                        outputArtifacts: ['source-output'],
                        version: '1',

                        configuration: {
                            ConnectionArn: 'connection.arn',
                            FullRepositoryId: 'org/repo',
                            BranchName: 'main',
                            OutputArtifactFormat: 'CODEBUILD_CLONE_REF',
                        },
                    }
                ],
            }]

        const pipelineStagesArg: pulumi.Input<pulumi.Input<inputs.codepipeline.PipelineStage>[]>

        const stages = pulumi.all([pipelineStagesArg, sourceStage]).apply(
            ([args, sourceStage]) => sourceStage.concat(args)
        )
Which also worked
Again, thank you 🙏
👍 1