bland-monitor-37952
07/02/2025, 12:30 PMInput
or Output
that may be undefined
, because it's an optional parameter, is it better to represent that as foo?: Output<string>
, or foo: Output<string | undefined>
in my class (and the same for Input
in my args
interface)?
Mainly I'm thinking for stuff like pulumi.all
, does it handle a given value being undefined
, or does it expect all values to be something that can be resolved to a concrete value at run-time, even if that concrete value is undefined
?
I can test this pretty easily and see if it works, but I was also wondering what would be recommended as best practise in Pulumi.little-cartoon-10569
07/02/2025, 8:46 PMOutput<string | undefined>
is my preference.
For inputs on my own component resources, I find that I rarely need to support optional parameters where the "optionality" is an output: that is, I know at code-writing time whether or not the value is getting passed in. So generally I provide those as optional Input<string>
parameters. However if you want to allow an Output<string | undefined>
to be a parameter, then obviously you have no choice.
I see both in Pulumi-provided code, but Input<string | undefined>
does seem to be more common.