typeof tests a declared variable or a property against "undefined"
What it finds
typeof x === "undefined" guards against reading a variable that may not exist at all, which is only possible for globals. For a variable declared in the file, or a property access, x === undefined asks the same and reads plainly.
Reported are comparisons of typeof with "undefined" when the operand is a variable declared in the file, or a member access that starts from one. Undeclared names, for which typeof is the only safe test, are left alone.
From the rule's source, typeof_on_declared_name.rs.
export function check(value: unknown, options: { name?: string }) { const a = typeof value === "undefined";tx0 reports: compare it with undefined directly const b = typeof options.name !== "undefined";tx0 reports: compare it with undefined directly const c = typeof someGlobal === "undefined"; return [a, b, c];} Turn it on, off or suppress it
The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/ts:typeof-on-declared-name" = "warning"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-on-declared-name] reason="..."tx0 explain tx0/ts:typeof-on-declared-name shows the same in the terminal. Found a false positive? Report it.