• Error
  • Reported by the type checker

TS2630

Cannot assign to '{0}' because it is a function.

A function declaration's name is used as an assignment target. Use a variable holding the function if it needs to change.

What it means

The left side of the assignment is a function declaration. Its name can't be rebound in TypeScript.

Example

index.ts
function log() {}
log = () => {};
export {};
ts-r-check -p tsconfig.json --pretty false ts-r output
index.ts(2,1): error TS2630: Cannot assign to 'log' because it is a function.

Recorded by node scripts/verify-examples.mjs with ts-r built from commit 6deaf01. The example uses the default tsconfig: strict, target: es2022, module: esnext, moduleResolution: bundler.

How to fix

  • Declare it as a variable when it needs to be replaceable: let log = () => {};.
  • Or give the replacement its own name.