A ! claims without a check that a value is neither null nor undefined
What it finds
user!.name: a non-null assertion tells the compiler that a value is not null or undefined without checking it. When the claim is wrong, the code fails at run time at a place the types said was safe. A check, a default with ?? or optional chaining handles the case instead.
Every ! assertion is reported; code where a value is known to be set by other means uses them on purpose, which is why the rule is strict.
From the rule's source, unchecked_bang.rs.
function first(items: string[] | undefined) { return items!.length;tx0 reports: this ! asserts a value is set without checking} 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:unchecked-bang" = "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:unchecked-bang] reason="..."tx0 explain tx0/ts:unchecked-bang shows the same in the terminal. Found a false positive? Report it.