unassignedVariables
Reports variables that are declared but never assigned a value.
✅ This rule is included in the ts untyped
preset.
Variables declared without an initializer and never assigned a value will always be undefined
.
This is often a mistake, such as forgetting to initialize a variable or assign to it before use.
Examples
Section titled “Examples”let value;console.log(value);
function calculate() { let result; return result;}
var unassigned: number;processValue(unassigned);
let value = 42;console.log(value);
function calculate() { let result = 0; return result;}
let assigned: number;assigned = 10;processValue(assigned);
Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”If you intentionally want to work with unassigned variables that default to undefined
, you might want to disable this rule.
However, it’s generally better to explicitly assign undefined
to make the intent clear.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- Biome:
noUnassignedVariables
- ESLint:
no-unassigned-vars
- Oxlint:
eslint/no-unassigned-vars
Made with ❤️🔥 in Boston by
Josh Goldberg and contributors.