Skip to content

no-non-null-assertion

Reports a non-null assertion (a!, a!.b) in a TypeScript file.

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.

Reported
a!.b;
a!!;
a!?.b;
a!?.();
a?.b!.c;
a![0];
`${a!.b}x`;
js:
lint:
rules:
no-non-null-assertion: warn # off (default), warn, error

Enabled 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.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
typescript-eslint no-non-null-assertion full