# Optional properties in object literals

**URL:** <https://es.discourse.group/t/optional-properties-in-object-literals/2075>\
**Category:** 💡 Ideas\
**Created:** [June 22, 2024, 12:15pm UTC](https://es.discourse.group/t/optional-properties-in-object-literals/2075 "2024-06-22T12:15:32Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![daniel.rentz](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/daniel.rentz/32/1946_2.png) [@daniel.rentz](https://es.discourse.group/u/daniel.rentz)\
**Post date:** [June 26, 2024, 8:26am UTC](https://es.discourse.group/t/optional-properties-in-object-literals/2075/4 "2024-06-26T08:26:26Z")

</div>

> [@Optional keys in objects](https://es.discourse.group/t/optional-keys-in-objects/523):
>
> I have typical problem with javascript. Say, I have an input object, which, in some cases, could be enrich with additional keys. I have two options how to do that. First: function enrich(input, optionalData) { return { ...input, additionalKey: optionalData } } Now I could have an object with { additionalKey: undefined }, which could lead to bugs. For example, additionalKey will be lost after JSON.stringify/parse. Another bug: check key with operator in ('additionalKey' in obj), whi…

---

_[View the full topic](https://es.discourse.group/t/optional-properties-in-object-literals/2075)._
