A built-in global is assigned another value

tx0/ts:global-assigndefaultwarningbug

What it finds

undefined = 0, Object = MyObject, JSON = null: assigning to a built-in global either fails, for the read-only undefined, NaN and Infinity, or replaces it for every other script and library in the program.

The name must refer to a well-known global that the file does not declare itself. Assignments inside an if that tests the same name with typeof, as a fallback for environments without it does, are left alone.

From the rule's source, global_assign.rs.

Example from the rule's tests
function setup(value: number) {  undefined = value;tx0 reports: this assignment replaces the built-in global undefined  JSON = null;tx0 reports: replaces the built-in global JSON  let Map = 1;  Map = 2;  return Map;}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

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:

tx0.toml
[rules]
"tx0/ts:global-assign" = "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:global-assign] reason="..."

tx0 explain tx0/ts:global-assign shows the same in the terminal. Found a false positive? Report it.