Skip to content

selfAssignments

Reports self-assignments which have no effect and are likely errors.

✅ This rule is included in the ts logical and logicalStrict presets.

Self-assignments where a variable is assigned to itself have no effect and typically indicate an incomplete refactoring or a copy-paste error. These assignments serve no purpose and should be removed or corrected to assign the intended value.

value =
const value: any
value
;
Error ts(2588) ― Cannot assign to 'value' because it is a constant.
count &&=
const count: any
count
;
Error ts(2588) ― Cannot assign to 'count' because it is a constant.
const flags: any
flags
.
any
value
||=
const flags: any
flags
.
any
value
;
data ??=
const data: any
data
;
Error ts(2588) ― Cannot assign to 'data' because it is a constant.

This rule is not configurable.

There are rarely valid reasons to use self-assignment. In cases where you need to trigger getters/setters or proxies, consider adding a comment explaining the intentional self-assignment.

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