Non-null assertion
This is how the comment reads inline, under the flagged line.
Why it matters
Non-null assertions skip the check the type system asked for. They are often added to quiet an error, not because the value is proven present.
What to do
Check for null and handle it, or narrow the type earlier.
Examples
const id = user!.id;
if (!user) throw new Error("no user");
const id = user.id;What it catches
It reads a pattern on each line, aware of strings and comments. Languages: TypeScript and JavaScript. Scope: All files. These cases are the rule's own tests: the first set must be flagged and the second must not.
Flagged
const id = user!.id;
go(map.get(k)!);
Left alone
if (!user) return;
const ne = a !== b;
Research
`any`, `as unknown as`, non-null `!`, and shapeless types (`Record<string, any>`, `dict[str, Any]`). Each one turns off type checking for the values it touches.
Turn it off or change it
In a config file for the CLI, or in the API's rules field:
{
"rules": {
"disable": [
"non-null-assertion"
],
"severity": {
"non-null-assertion": "medium"
}
}
}
!tells the compiler this can't be null. If it can, this crashes.