When spreading an object conditionally, we have two style: ? :
and &&
. I prefer user consistently to use &&
.
const name = Math.random() > 0.5 'foo' : undefined;
const student = {age: 12, ...(name&&{name})};
const name = Math.random() > 0.5 'foo' : undefined;
const student = {age: 12, ...(name ? {name} : {})};
consistent-conditional-object-spread
No response
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too