A variable is declared with undefined as its initial value

tx0/ts:undefined-initializerstrictwarningstyle

What it finds

let x = undefined; spells out what let x; does anyway: a variable declared without a value starts as undefined.

Declarations with let are reported when the value is the global undefined, not a local variable of that name. A var is left alone: in a loop, var x; keeps the value of the previous iteration where var x = undefined; resets it. The fix removes the initializer; it is safe in JavaScript and unsafe in TypeScript, where a declaration without a value can make the compiler report a use before assignment.

From the rule's source, undefined_initializer.rs.

Example from the rule's tests
function f(undefinedValue: unknown) {  let a = undefined;tx0 reports: starts as undefined  let b;  var c = undefined;  const d = undefined;  return [a, b, c, d, undefinedValue];}function g(undefined: number) {  let x = undefined;  return x;}
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 from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:

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

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