typescript lint_error ai_generated true

error TS6133: 'x' is declared but its value is never read

ID: typescript/ts6133-declared-not-read

Also available as: JSON · Markdown
98%Fix Rate
95%Confidence
50Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
5 active

Root Cause

Unused variable or import. TypeScript reports this when noUnusedLocals/noUnusedParameters is enabled.

generic

Workarounds

  1. 98% success Remove the unused variable or import
    // Remove the unused variable/import:
    // import { unused } from './module';  // delete this line
    
    // Or prefix with _ if intentionally unused:
    const _intentionallyUnused = getValue();
    
    // In tsconfig.json, this is controlled by:
    // "noUnusedLocals": true,
    // "noUnusedParameters": true

    Sources: https://www.typescriptlang.org/tsconfig/#noUnusedLocals

  2. 92% success Prefix with underscore if intentionally unused: _unusedParam
    function handler(_req: Request, res: Response) { ... }

    Sources: https://www.typescriptlang.org/tsconfig/#noUnusedParameters

Dead Ends

Common approaches that don't work:

  1. Disable noUnusedLocals in tsconfig 65% fail

    Disables a useful lint rule across the entire project

  2. Assign to void: void unusedVar 70% fail

    Obscure and confusing — just remove or prefix with underscore

Error Chain

Frequently confused with: