no-non-null-asserted-optional-chain
JavaScript / TypeScriptsuspiciousno fixdefault: offjs/typescript-eslint-recommendedjs/biome-recommendedjs/oxlint
What it does
Section titled “What it does”Reports a non-null assertion on the end of an optional chain: a?.b! and (a?.b)!. a?.b!.c is not reported.
Why it matters
Section titled “Why it matters”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.
Example
Section titled “Example”...function g<T extends string>(x: T) {}let a = b?.c!;let d = (b?.c)!;let e = b!.c;b?.c()!;b?.c!.d;Configuration
Section titled “Configuration”js: lint: rules: no-non-null-asserted-optional-chain: warn # off (default), warn, errorEnabled 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.
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-asserted-optional-chain |
full |