A ! is applied to a value that can never be null or undefined
What it finds
"label"!, new Map()!, value!!: a non-null assertion on a value that can never be null or undefined, such as a literal other than null, a new object, a function, this, or a value already asserted, does nothing. It suggests a doubt that does not exist, or a leftover from code that changed.
The fix drops the ! and is safe.
From the rule's source, needless_non_null.rs.
function f(value: string | undefined) { const a = "label"!;tx0 reports: this value can never be null or undefined const b = new Map()!;tx0 reports: this value can never be null or undefined const d = value!!;tx0 reports: this value is already asserted with ! const c = value!; return [a, b, c];} Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/ts:needless-non-null" = "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:needless-non-null] reason="..."tx0 explain tx0/ts:needless-non-null shows the same in the terminal. Found a false positive? Report it.