no-non-null-assertion
What it does
Section titled “What it does”Reports a non-null assertion (a!, a!.b) in a TypeScript file.
Why it matters
Section titled “Why it matters”a! tells the compiler the value is not null or undefined without checking it. When the assumption is wrong the program fails at run time with a TypeError, in the place the type system was meant to protect.
To fix, check the value (if (a)) or use optional chaining (a?.b) and handle the missing case.
Example
Section titled “Example”a!.b;a!!;a!?.b;a!?.();a?.b!.c;a![0];`${a!.b}x`;Configuration
Section titled “Configuration”js: lint: rules: no-non-null-assertion: warn # off (default), warn, errorEnabled by the presets: js/biome-recommended.
Suppress one line with sudsy-disable-next-line no-non-null-assertion in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools; Sudsy reports what each upstream rule reports.
| Tool | Rule | Match |
|---|---|---|
| typescript-eslint | no-non-null-assertion |
full |