arrayTernarySpreadingConsistency
Reports inconsistent types when spreading a ternary in an array literal.
✅ This rule is included in the tsstylisticandstylisticStrictpresets.
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 const condition: true
condition = true;const const result: (string | number)[]
result = [1, ...(const condition: true
condition ? [2, 3] : "")];const const flag: false
flag = false;const const items: string[]
items = [...(const flag: false
flag ? "abc" : [])];const const condition: true
condition = true;const const result: number[]
result = [1, ...(const condition: true
condition ? [2, 3] : [])];const const flag: false
flag = false;const const items: string[]
items = [...(const flag: false
flag ? "abc" : "")];const const value: true
value = true;const const array: number[]
array = [0, ...(const value: true
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 ❤️🔥 around the world by
the Flint team and contributors.