Is it possible to use the javascript spread operat...
# general
s
Is it possible to use the javascript spread operator on an input? well, i guess, more so a workaround?
Copy code
async create({
    addtOrigins = []
  }: {
    addtOrigins?: aws.cloudfront.DistributionArgs['origins'];
  }): Promise<aws.cloudfront.Distribution> {
    const apiDistribution = new aws.cloudfront.Distribution(
      `distribution`,
      {
        origins: [
          {
            // removed, but assume one exists here.
          },
          ...addtOrigins
        ],
there is a lot more to that but essentially i am looking to add anything additional that i passed to this helper function and spread them into some existing default configuration... however, it appears that when i utilize the pulumi aws.cloudfront.DistributionArgs i am dealing with an input which will not allow me to spread this in.
g
hm i dont think there’s a problem with this approach. possible issue is that addtOrigins is optional which you cant spread if it’s undefined, you can use a default like `addtOrigins: <type> = []`so its an array even if nothing is passed in
oh jk you have the default there. what’s the TS error you’re getting
s
Type 'Input<Input<DistributionOrigin>[]>' must have a '[Symbol.iterator]()' method that returns an iterator.
g
hmm tricky
try this
Copy code
origins: pulumi
      .output(addtOrigins)
      .apply((addtOrigins) => [...addtOrigins, {...}]),
actually this is the right way: replace the type of
addtOrigins
with the real object type (not wrapped in pulumi.Input):
aws.types.input.cloudfront.DistributionOrigin[];
s
aha! thanks 🙂
i've done that before i just could not quite remember how i had done it 🙂