constantAssignments
Reports attempting to reassign variables declared with const.
✅ This rule is included in the ts untyped
preset.
The const
keyword creates a read-only reference to a value, preventing reassignment.
While properties of const objects and elements of const arrays can be mutated, the binding itself cannot be reassigned.
Attempting to reassign a const variable results in a runtime error.
Examples
Section titled “Examples”const value = 1;value = 2;
const result = getValue();result = getOtherValue();
const counter = 0;counter++;
const { property } = object;property = "new value";
for (const item of items) { item = processItem(item);}
let value = 1;value = 2;
const object = { value: 1 };object.value = 2;
const array = [1, 2, 3];array.push(4);
const { property } = object;console.log(property);
for (let item of items) { item = processItem(item);}
Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”This rule should always be enabled. Reassigning a const variable is a runtime error in JavaScript and TypeScript, so this rule helps catch such issues during development.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- Biome:
noConstAssign
- Deno:
no-const-assign
- ESLint:
no-const-assign
- Oxlint:
eslint/no-const-assign
Made with ❤️🔥 in Boston by
Josh Goldberg and contributors.