useValidTypeof
Diagnostic Category: lint/suspicious/useValidTypeof
Since: v1.0.0
Sources:
- Same as:
valid-typeof
This rule checks that the result of a `typeof’ expression is compared to a valid value.
Examples
Section titled ExamplesInvalid
Section titled Invalidcode-block.js:1:16 lint/suspicious/useValidTypeof ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ “strnig” is not a valid typeof value.
> 1 │ typeof foo === “strnig”;
│ ^^^^^^^^
2 │
code-block.js:1:15 lint/suspicious/useValidTypeof ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ “undefimed” is not a valid typeof value.
> 1 │ typeof foo == “undefimed”;
│ ^^^^^^^^^^^
2 │
code-block.js:1:15 lint/suspicious/useValidTypeof ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ “nunber” is not a valid typeof value.
> 1 │ typeof bar != “nunber”;
│ ^^^^^^^^
2 │
code-block.js:1:16 lint/suspicious/useValidTypeof ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Invalid typeof comparison.
> 1 │ typeof foo === undefined;
│ ^^^^^^^^^
2 │
ℹ Compare with one of the following string literals:
- “bigint”
- “boolean”
- “function”
- “number”
- “object”
- “string”
- “symbol”
- “undefined”
code-block.js:1:15 lint/suspicious/useValidTypeof ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Invalid typeof comparison.
> 1 │ typeof foo == 0;
│ ^
2 │
ℹ Compare with one of the following string literals:
- “bigint”
- “boolean”
- “function”
- “number”
- “object”
- “string”
- “symbol”
- “undefined”