TypeScript — TS6133: Variable is declared but never read
Resolve unused variable errors by removing dead code, prefixing intentional ignores, or adjusting lint and compiler settings.
Symptoms
- error TS6133: 'x' is declared but its value is never read
- The build fails after enabling noUnusedLocals
- Unused imports block the build
- Intentional unused parameters in callbacks warn
Possible causes
- Dead variables or imports left after a refactor
- noUnusedLocals or noUnusedParameters was enabled
- A callback must accept a parameter it does not use
- An import is only needed for its side effects
Diagnosis steps
Remove genuinely unused declarations
npx tsc --noEmitInterpretation
Each reported name is either removable dead code or intentionally unused and should be handled explicitly.
Prefix intentional unused parameters
function cb(_event: Event) {}Interpretation
An underscore prefix marks a knowingly unused binding so the compiler permits it.
Check compiler options
grep -n "noUnusedLocals\|noUnusedParameters" tsconfig.jsonInterpretation
Knowing the flag explains the failure and confirms it is a policy, not a bug.
Root cause
A declared variable, import or parameter is never read, which strict settings treat as an error to keep the code clean.
Fix
Delete dead declarations, prefix intentionally unused parameters with an underscore, and use a side-effect import for modules imported only for their effect.
Verify the fix
Rerun the type checker and confirm the errors are gone, and confirm the build still passes without accidental removal of needed code.
Symptom walkthrough
The compiler reports TS6133 for declarations that are never read, usually after enabling noUnusedLocals and noUnusedParameters. The failures are often harmless leftovers from a refactor, but a genuinely unused import or variable can also indicate a mistake where the intended value was never used, which is why strict settings flag them.
Fix in practice
Remove declarations that are truly dead, prefix parameters you must accept but do not use with an underscore, and use a side-effect import when a module is needed only for its initialization. Do not simply silence the rule globally, since it catches real mistakes.
Verification
Rerun the type checker and confirm the errors clear, then run the build and tests to confirm no needed code was removed accidentally. A clean build with intact behavior confirms the cleanup was correct.
Diagnostic commands
Check the behavior with commands like these:
npx tsc --noEmit
function cb(_event: Event) {}
grep -n "noUnusedLocals\|noUnusedParameters" tsconfig.json