chainedAssignments
Reports using chained assignment expressions (e.g., a = b = c).
✅ This rule is included in the tsstylisticandstylisticStrictpresets.
Chained assignments can be hard to read and can lead to unexpected behavior with variable scoping and type inference. Each assignment creates a reference to the same value, which may cause confusion when dealing with mutable values.
Examples
Section titled “Examples”let let first: any
first;let let second: any
second;let first: any
first = let second: any
second = 1;let let first: any
first;let let second: any
second;let let third: any
third;let first: any
first = let second: any
second = let third: any
third = const getValue: () => number
getValue();function function process(value: number): void
process(value: number
value: number): void { let let result: any
result; let let cache: any
cache; let result: any
result = let cache: any
cache = value: number
value * 2;}let let first: any
first;let let second: any
second;let first: any
first = 1;let second: any
second = 1;let let first: any
first;let let second: any
second;let let third: any
third;const const value: number
value = const getValue: () => number
getValue();let first: any
first = const value: number
value;let second: any
second = const value: number
value;let third: any
third = const value: number
value;function function process(value: number): void
process(value: number
value: number): void { let let result: any
result; let let cache: any
cache; const const computed: number
computed = value: number
value * 2; let result: any
result = const computed: number
computed; let cache: any
cache = const computed: number
computed;}Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”If your codebase frequently uses chained assignments as a concise idiom and you find them readable, you might choose to disable this rule. However, breaking chained assignments into separate statements generally improves code clarity and reduces potential for bugs.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- ESLint:
no-multi-assign - Oxlint:
eslint/no-multi-assign
Made with ❤️🔥 around the world by
the Flint team and contributors.