• Error
  • Reported by the type checker

TS2448

Block-scoped variable '{0}' used before its declaration.

A let or const variable is read before the line that declares it. Move the declaration up, or move the use after it.

What it means

let and const variables exist from the start of their block but can't be read until their declaration has run (the temporal dead zone). A use that appears earlier in the same scope throws at runtime, so it is reported.

Example

index.ts
console.log(total);
const total = 10;
ts-r-check -p tsconfig.json --pretty false ts-r output
index.ts(1,13): error TS2448: Block-scoped variable 'total' used before its declaration.

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

  • Move the declaration above its first use.
  • If the use is inside a function that runs later, that's fine; this error is only for code that runs before the declaration.