(typescript) How can I append a key value to this...
# general
a
(typescript) How can I append a key value to this array? public static tags: pulumi.Input<{[key: string]: pulumi.Input<string>}>; tags = { "key1": "val1", "key2": "val2" }; Doing this replaces all the current tags with just the one key/value pair tags && { "key3": "val3" }
b
Is there a reason the value type needs to be
pulumi.Input<string>
? If this is for AWS Tags they tend to be
pulumi.Input<{[key: string]: string}>
and then before you pass it to the AWS Resource you can just use and manipulate a normal
{[key: string]: string}
because the
pulumi.Input<{[key: string]: string}>
will accept that
a
Yes, this is a Pulumi data type so it needs to be that. I didn't define it. Anyway I asked how I can append to the tags value. You said to manipulate a normal {key: string}: string}. How do I go about appending to that?
b
Can you point to reference that is expecting a type of
pulumi.Input<{[key: string]: pulumi.Input<string>}>
? I want to be certain that is necessary because that is especially painful to work with. If that is 100% the correct type - then just declare it externally as
{[key: string]: pulumi.Input<string>}
and do everything you need to do like that before passing it in.
A normal
{[key: string]: string}
is just a standard typescript object with a string value type.
a
I did some playing around and you are correct, I can substitute {[key: string]: string}. How can I append to that?
b
tags["key3"] = "val3"
or if it is allowed
tags.key3 = "val3"
a
well that was easy. I don't work with TS very often and most languages I know won't do dynamic appending. Awesome tho. Thank you very much for the help
b
no problem, good luck
👍 1
195 Views