classAssignments
Reports reassigning class declarations.
✅ This rule is included in the ts untyped
preset.
Reassigning a class declaration can lead to unexpected behavior and makes code harder to understand. Class declarations are typically intended to be immutable references, and reassigning them can cause confusion about which class is being used.
Examples
Section titled “Examples”class MyClass {}MyClass = 0;
class Counter {}Counter++;
class Data {}Data = null;
class MyClass {}const instance = new MyClass();
class Counter {}const value = Counter;
class MyClass {}const derived = class extends MyClass {};
Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”If your project uses class reassignments as a design pattern, you might not be able to immediately enable this rule. Consider using differently-named variables instead to gain mutable references to classes.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- Biome:
noClassAssign
- Deno:
no-case-assign
- ESLint:
no-class-assign
- Oxlint:
eslint/no-class-assign
Made with ❤️🔥 in Boston by
Josh Goldberg and contributors.