useValidTypeof (since v1.0.0)
Diagnostic Category: lint/suspicious/useValidTypeof
Sources:
- Same as: 
valid-typeof 
This rule verifies the result of typeof $expr unary expressions is being compared to valid values, either string literals containing valid type names or other typeof expressions
Examples
Section titled ExamplesInvalid
Section titled Invalidtypeof foo === "strnig"code-block.js:1:16 lint/suspicious/useValidTypeof ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  ✖ Invalid `typeof` comparison value
  
  > 1 │ typeof foo === "strnig"
      │                ^^^^^^^^
    2 │ 
  
  ℹ not a valid type name
  
typeof foo == "undefimed"code-block.js:1:15 lint/suspicious/useValidTypeof ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  ✖ Invalid `typeof` comparison value
  
  > 1 │ typeof foo == "undefimed"
      │               ^^^^^^^^^^^
    2 │ 
  
  ℹ not a valid type name
  
typeof bar != "nunber"code-block.js:1:15 lint/suspicious/useValidTypeof ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  ✖ Invalid `typeof` comparison value
  
  > 1 │ typeof bar != "nunber"
      │               ^^^^^^^^
    2 │ 
  
  ℹ not a valid type name
  
typeof bar !== "fucntion"code-block.js:1:16 lint/suspicious/useValidTypeof ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  ✖ Invalid `typeof` comparison value
  
  > 1 │ typeof bar !== "fucntion"
      │                ^^^^^^^^^^
    2 │ 
  
  ℹ not a valid type name
  
typeof foo === undefinedcode-block.js:1:16 lint/suspicious/useValidTypeof  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  ✖ Invalid `typeof` comparison value
  
  > 1 │ typeof foo === undefined
      │                ^^^^^^^^^
    2 │ 
  
  ℹ not a string literal
  
  ℹ Unsafe fix: Compare the result of `typeof` with a valid type name
  
    1 │ typeof·foo·===·"undefined"
      │                +         +
typeof bar == Objectcode-block.js:1:15 lint/suspicious/useValidTypeof  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  ✖ Invalid `typeof` comparison value
  
  > 1 │ typeof bar == Object
      │               ^^^^^^
    2 │ 
  
  ℹ not a string literal
  
  ℹ Unsafe fix: Compare the result of `typeof` with a valid type name
  
    1   │ - typeof·bar·==·Object
      1 │ + typeof·bar·==·"object"
    2 2 │   
  
typeof foo === bazcode-block.js:1:16 lint/suspicious/useValidTypeof ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  ✖ Invalid `typeof` comparison value
  
  > 1 │ typeof foo === baz
      │                ^^^
    2 │ 
  
  ℹ not a string literal
  
typeof foo == 5code-block.js:1:15 lint/suspicious/useValidTypeof ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  ✖ Invalid `typeof` comparison value
  
  > 1 │ typeof foo == 5
      │               ^
    2 │ 
  
  ℹ not a string literal
  
typeof foo == -5code-block.js:1:15 lint/suspicious/useValidTypeof ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  ✖ Invalid `typeof` comparison value
  
  > 1 │ typeof foo == -5
      │               ^^
    2 │ 
  
  ℹ not a string literal
  
Valid
Section titled Validtypeof foo === "string"typeof bar == "undefined"typeof bar === typeof qux