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.
Examples
Section titled “Examples”const condition = true;const result = [1, ...(condition ? [2, 3] : "")];const flag = false;const items = [...(flag ? "abc" : [])];const condition = true;const result = [1, ...(condition ? [2, 3] : [])];const flag = false;const items = [...(flag ? "abc" : "")];const value = true;const array = [0, ...(value ? [1] : [2])];Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”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.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”
Made with ❤️🔥 in Boston by
Josh Goldberg and contributors.