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;

How to use

To enable this rule in the CLI or using the config file, you can use:

bash
oxlint --deny valid-typeof
json
{
  "rules": {
    "valid-typeof": "error"
  }
}

References

Released under the MIT License.