Skip to content

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.

let value;
console.log(value);
function calculate() {
let result;
return result;
}
var unassigned: number;
processValue(unassigned);

This rule is not configurable.

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.

Made with ❤️‍🔥 in Boston by Josh Goldberg and contributors.