Skip to content

no-non-null-asserted-optional-chain

Reports a non-null assertion on the end of an optional chain: a?.b! and (a?.b)!. a?.b!.c is not reported.

An optional chain returns undefined when a is missing, so asserting its result is not undefined contradicts the chain, and the program will fail at run time when the assumption is wrong.

To fix, handle the missing value, or drop ?. if a cannot be null.

Reported
...
function g<T extends string>(x: T) {}
let a = b?.c!;
let d = (b?.c)!;
let e = b!.c;
b?.c()!;
b?.c!.d;
js:
lint:
rules:
no-non-null-asserted-optional-chain: warn # off (default), warn, error

Enabled by the presets: js/typescript-eslint-recommended, js/biome-recommended, js/oxlint.

Suppress one line with sudsy-disable-next-line no-non-null-asserted-optional-chain 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-asserted-optional-chain full