Open zanminkian opened 1 month ago
This kind of like short circuit
foo && bar();
But I prefer
if (foo) {
bar();
}
So I prefer the ternary version, but I use {...(name ? {name} : undefined)}
I prefer &&
too in this case. There is really no benefit of the verbose ternary version. However, it should include an option to choose the style.
ONE benefit in werid JavaScript world.
({...(document.all && {foo: 1})})
// VS
({...(document.all ? {foo: 1} : undefined)})
Just kidding.
From my point of view, this rule only work when the variable name is the same as the property name. For example:
Work:
const student = {...(name?{name}:{})}
// or
const student = {...(name&&{name})}
Not work:
const student = {...(name?{age}:{})}
// or
const student = {...(name&&{age})}
this rule only work when the variable name is the same as the property name.
I don't think so, the name doesn't matter. Spread any falsely value in object literal does not add any property (of cause except HTMLDDA).
Accepted
Description
When spreading an object conditionally, we have two style:
? :
and&&
. I prefer user consistently to use&&
.Pass
Fail
Proposed rule name
consistent-conditional-object-spread
Additional Info
No response