I want to set a property to a value only if the value is not undefined, otherwise I don't want to set the property.
This is how I usually handle this scenario:
const payload: UpdateDistributionCommandInput = {
Id: cloudFrontId,
DistributionConfig: {
...distribution.DistributionConfig,
Aliases: {
Items: modifiedAliasItems,
Quantity: modifiedAliasItems.length
}
}
}
if (typeof distribution.ETag === "string") {
payload.IfMatch = distribution.ETag;
}
const updateDistributionCommand = new UpdateDistributionCommand(payload)
It looks a bit verbose and messy to me. Is there any shorter syntax for this, or other way of approaching this scenario?