跳至內容

eslint/valid-typeof 正確性

此規則預設為啟用。
🛠️ 此規則對於某些違規行為提供自動修正。

作用

強制將 typeof 運算式與有效的字串進行比較

為什麼這不好?

typeof 運算子的結果與其他字串文字進行比較通常是輸入錯誤。

範例

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

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

參考

根據 MIT 許可發布。