Prefer consistent types when spreading a ternary in an array literal ​
💼 This rule is enabled in the ✅ recommended
config.
🔧 This rule is automatically fixable by the --fix
CLI option.
When spreading a ternary in an array, we can use both []
and ''
as fallbacks, but it's better to have consistent types in both branches.
Fail ​
js
const array = [
a,
...(foo ? [b, c] : ''),
];
js
const array = [
a,
...(foo ? 'bc' : []),
];
Pass ​
js
const array = [
a,
...(foo ? [b, c] : []),
];
js
const array = [
a,
...(foo ? 'bc' : ''),
];