TypeScript Reference ยท Error Codes Worth Knowing
TypeScript error TS6133: declared but never used
TS6133 reports an unused local, import, parameter or private member when noUnusedLocals or noUnusedParameters is on. Learn what counts as used and how to resolve it.
TS6133 reads 'x' is declared but its value is never read. (older versions said declared but never used). It is reported for unused imports, local variables, function parameters and private class members, but only when the matching option is on: noUnusedLocals for variables, imports and private members, noUnusedParameters for parameters. Neither is part of strict, so a default --strict project does not show the error. Editors show the same finding as a faded name, without failing the build.
The message says "never read", not "never mentioned". A variable that is only assigned to also counts as unused, because nothing ever observes its value.
function f(a: number, b: number) { return a; } // b: TS6133 with noUnusedParameters let unused = 5; // TS6133 with noUnusedLocals
Try it
With plain --strict, as in the runner, the first example compiles, which shows that the error is opt-in. The options are read-only snippets below because they can only be set in tsconfig.json.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.
{ "compilerOptions": { "noUnusedLocals": true, "noUnusedParameters": true } }
Syntax
| Declaration | Reported when | Typical fix |
|---|---|---|
| Import | Never referenced (type-only use counts as use) | Delete it, or use import type if only types are needed. |
| Local variable or function | Never read | Delete it, or use the value. |
Parameter (needs noUnusedParameters) |
Never read | Remove it, or rename with a leading underscore. |
Private property or method (private or #name) |
Never read | Delete it, or make it used. |
| Destructured name | Never read | Remove it, use a hole, or rename with _ (locals only exempt in some forms). |
| Type parameter | Never used | Remove it. TS6133 is reported for unused type parameters under noUnusedParameters. |
Usage notes
- Underscore convention. Names starting with
_are ignored for parameters, and for destructured variables andcatchbindings in modern compilers. It is the intended escape hatch. - Assigned but never read still counts as unused, which helps find forgotten state.
- Exported declarations are not unused, because other files may import them. Only module-private code is checked.
- Linters complement it. ESLint's unused-variable rules can ignore patterns the compiler cannot, and can fix imports automatically; many teams enable only one of the two.
- Editor action. "Remove unused imports" and
organize importsclean most TS6133 instances in one step. - In CI turn the options on for production code and leave them off for scratch or generated code, using separate tsconfig files.
Related
- noUnusedLocals, noUnusedParameters, import type, TS2578
- Lessons: tsconfig, Best practices