Skip to content

arrayTernarySpreadingConsistency

Reports inconsistent types when spreading a ternary in an array literal.

✅ This rule is included in the ts stylistic preset.

When spreading a ternary expression in an array literal, prefer using consistent types for both branches. Mixing arrays with empty strings as fallbacks reduces code clarity.

const condition = true;
const result = [1, ...(condition ? [2, 3] : "")];
const flag = false;
const items = [...(flag ? "abc" : [])];

This rule is not configurable.

If you intentionally use mixed types in ternary spreads for specific edge cases, or if your codebase has established patterns that mix array and string types, you may want to disable this rule.

Made with ❤️‍🔥 in Boston by Josh Goldberg and contributors.