undefinedVariables
Reports using variables that are not defined.
✅ This rule is included in the ts untyped
preset.
Variables must be declared before they can be used in JavaScript. Using undefined variables will cause a ReferenceError at runtime. This rule helps catch typos and missing declarations early in development.
Examples
Section titled “Examples”console.log(undefinedVar);
function calculate() { return result;}
const value = first + second;
const value = 5;console.log(value);
function calculate(input: number) { const result = input * 2; return result;}
const first = 1;const second = 2;const value = first + second;
Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”This rule can be safely disabled if you’re using TypeScript’s type checking, which will catch undefined variables through its own error reporting.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- Biome:
noUndeclaredVariables
- ESLint:
no-undef
- Oxlint:
eslint/no-undef
Made with ❤️🔥 in Boston by
Josh Goldberg and contributors.