functionAssignments
Reports reassigning variables declared with function declarations.
✅ This rule is included in the ts untyped
preset.
Reassigning a function declaration can make code harder to understand and maintain. Function declarations are hoisted to the top of their scope, and reassigning them can lead to unexpected behavior.
Examples
Section titled “Examples”function calculate(value: number): number { return value * 2;}
calculate = (value: number) => value * 3;
function processData(): void { console.log("Processing...");}
processData = null;
function getValue(): number { return 42;}
getValue++;
function calculate(value: number): number { return value * 2;}
const result = calculate(10);
const processData = function (): void { console.log("Processing...");};
processData = () => { console.log("Different processing");};
let getValue = (): number => { return 42;};
getValue = () => 100;
Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”If you’re working in an existing codebase where reassigning function declarations is a common pattern and refactoring would be too costly, you might choose to disable this rule. However, using function expressions or const variables is generally a better practice when reassignment is needed.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- Biome:
noFunctionAssign
- Deno:
no-func-assign
- ESLint:
no-func-assign
- Oxlint:
eslint/no-func-assign
Made with ❤️🔥 in Boston by
Josh Goldberg and contributors.