Skip to content

chainedAssignments

Reports using chained assignment expressions (e.g., a = b = c).

✅ This rule is included in the ts stylistic preset.

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.

let first;
let second;
first = second = 1;
let first;
let second;
let third;
first = second = third = getValue();
function process(value: number): void {
let result;
let cache;
result = cache = value * 2;
}

This rule is not configurable.

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.

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