Skip to content

eslint/valid-typeof Correctness

This rule is turned on by default.
🛠️ An auto-fix is available for this rule for some violations.

What it does

Enforce comparing typeof expressions against valid strings

Why is this bad?

It is usually a typing mistake to compare the result of a typeof operator to other string literals.

Example

js
// requireStringLiterals: false
// incorrect:
typeof foo === "strnig";
// correct:
typeof foo === "string";
typeof foo === baz;

// requireStringLiterals: true
// incorrect:
typeof foo === baz;

References

Released under the MIT License.