Skip to content

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.

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++;

This rule is not configurable.

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.

Made with ❤️‍🔥 in Boston by Josh Goldberg and contributors.