Optional spreading proposal

Iterating on submitted idea Optional spreading and es-disscuss e-mail thread under title "[Proposal] Optional spreading"

{...null} and {...void 0} both return {} already, so the new syntax is not needed for object spreading.

An alternative would be to have [...x] tolerate nullish values for x.

1 Like

indeed, the alternative looks good, but it is possible that it is not backward compatible, in case of

try {
} catch (err) {
  //...my logic

but not sure about the approach committee has for breaking changes, maybe it is acceptable

Given that this is a relatively rare use case, I don’t find this too bad:

[...(arrayOrNullish ?? [])]
1 Like