Skip to content

returnAssignments

Reports using assignment expressions in return statements.

✅ This rule is included in the ts stylistic and stylisticStrict presets.

Using assignments in return statements can make code harder to read and can lead to confusion about whether the assignment or the returned value is the primary intent. Assignment expressions return the assigned value, but mixing assignment with return makes the control flow less clear.

function
function getValue(): number
getValue
() {
let
let value: any
value
;
return (
let value: any
value
= 1);
}
function
function process(): any
process
() {
let
let result: any
result
;
return (
let result: any
result
=
const calculate: any
calculate
());
}
const
const arrow: () => number
arrow
= () => (value = 42);
Error ts(2588) ― Cannot assign to 'value' because it is a constant.
function
function compound(): any
compound
() {
let
let count: any
count
;
return (
let count: any
count
+= 5);
}

This rule is not configurable.

If your codebase uses assignments in return statements as a common idiom and you find them readable, you might choose to disable this rule. However, separating assignments from return statements generally improves code clarity and reduces potential for confusion.

Made with ❤️‍🔥 around the world by the Flint team and contributors.