undefinedTypeofChecks
Reports typeof undefined checks.
✅ This rule is included in the ts stylistic presets.
Using typeof x === "undefined" is verbose and can be simplified to x === undefined.
Direct comparisons are clearer and more concise.
Examples
Section titled “Examples”if (typeof value === "undefined") { // handle undefined}if (typeof value !== "undefined") { // value is defined}if (value === undefined) { // handle undefined}if (value !== undefined) { // value is defined}Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”In rare cases where you need to check for undefined in a global scope where undefined might be shadowed,
typeof checks are safer.
However, in modern JavaScript, this is very uncommon.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- ESLint:
unicorn/no-typeof-undefined - Oxlint:
unicorn/no-typeof-undefined
Made with ❤️🔥 in Boston by
Josh Goldberg and contributors.