The result of typeof is compared with a value it never has
What it finds
typeof x === "strnig": typeof gives one of eight strings, so a comparison of its result with any other string, or with something that is not a string at all such as undefined, has a fixed outcome and is almost always a typo.
The eight are undefined, object, boolean, number, bigint, string, symbol and function, and old versions of Internet Explorer also gave unknown for some host objects, which code that supports them still tests. Only literals are compared, and undefined only when it is the global one.
From the rule's source, typeof_comparison.rs.
function check(value: unknown) { if (typeof value === "strnig") { // want "`typeof` never gives "strnig"; did you mean "string"?" return 1; } if (typeof value == "undefined" || typeof value === "bigint" || typeof value !== "unknown") { return 2; } if ("nmber" !== typeof value) { // want "did you mean "number"?" return 3; } if (typeof value === undefined) {tx0 reports: never undefined return 4; } if (typeof value === "array") { // want "`typeof` never gives "array"" return 5; } return typeof value === typeof check;} Turn it on, off or suppress it
The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:
[rules]
"tx0/ts:typeof-comparison" = "off"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/ts:typeof-comparison] reason="..."tx0 explain tx0/ts:typeof-comparison shows the same in the terminal. Found a false positive? Report it.