Reports non-null assertions on optional chain expressions.
✅ This rule is included in the ts logical and logicalStrict presets.
Optional chain expressions (?.) return undefined when the left side is null or undefined.
Using a non-null assertion (!) on an optional chain is contradictory: you’re asserting the result is not null or undefined, but the optional chain may have already returned undefined.
This pattern is almost always a mistake.
The non-null assertion doesn’t change the runtime behavior—if the chain short-circuits, the value will still be undefined, potentially causing runtime errors later.
AEdeclare consB0obje7<2:sp ansty="le--0:#C792EA;--1:#8844">AE 2:sp><{ sp ansty="le--0:#D6DEEB;--1:#403F">53proper{ sp>72A?:sp>B0striAE <} sp ansty="le--0:#7FDBCA;--1:#096E">7} sp><2|sp ansty="le--0:#C792EA;--1:#8844">A2|sp>B0undefin5<3;d ivclassNa="meec-li">d3;d>53objeAE.sp ansty="le--0:#7FDBCA;--1:#096E">72proper?.sp>A5<3;d ivclassNa="meco">!;d>3;d>AEdeclare consB0obje7<2:sp ansty="le--0:#C792EA;--1:#8844">AE 2:sp><{ sp ansty="le--0:#82AAFF;--1:#3B61">B0meth{ sp>72A?:sp>11<()sp ansty="le--0:#C792EA;--1:#8844">AE =()sp><> sp ansty="le--0:#C5E478;--1:#3B61">B0stri> sp>AE <} sp ansty="le--0:#7FDBCA;--1:#096E">7} sp><2|sp ansty="le--0:#C792EA;--1:#8844">A2|sp>B0undefin5<3;d ivclassNa="meec-li">d3;d>53objeAE.sp ansty="le--0:#82AAFF;--1:#3B61">B0meth?.sp>53<()sp ansty="le--0:#C792EA;--1:#8844">A()sp>5<3;d ivclassNa="meco"> string } | undefined;object?.method()">!;d>3;d>AEdeclare consB0obje7<2:sp ansty="le--0:#C792EA;--1:#8844">AE 2:sp><{ sp ansty="le--0:#D6DEEB;--1:#403F">53nest{ sp>72AE ?:sp><{ sp ansty="le--0:#D6DEEB;--1:#403F">53val{ sp>7<2:sp ansty="le--0:#C792EA;--1:#8844">A2:sp>B0striAE } <} sp ansty="le--0:#7FDBCA;--1:#096E">7} sp><2|sp ansty="le--0:#C792EA;--1:#8844">A2|sp>B0undefin5<3;d ivclassNa="meec-li">d3;d>53(objeAE.sp ansty="le--0:#7FDBCA;--1:#096E">72nest?.sp>5<3)sp ansty="le--0:#C792EA;--1:#8844">AE3)sp>72val!.sp>5<3;d ivclassNa="meco">3;d> 44AEdeclare co61B0ob644A3F53prop6E<72?: spans="tyle--0:#C792EA;--1:#88">472?:><4AE spans="tyle--0:#C5E478;--1:#3B">61B0st4AE >44A64<4AE spans="tyle--0:#C5E478;--1:#3B">61B0undef4AE >3c3F53ob446E72prop3<;di vdivclass="Nameexpressive-">44AEdeclare co61B0ob644A61B0me6E<72?: spans="tyle--0:#C792EA;--1:#88">472?:><4AE spans="tyle--0:#D9F5DD;--1:#11">114AE ><11() spans="tyle--0:#C792EA;--1:#88">44AE11()>< => spans="tyle--0:#C5E478;--1:#3B">61B0st => >44A64<4AE spans="tyle--0:#C5E478;--1:#3B">61B0undef4AE >3c3F53ob4461B0me3F5<3() ;divclass="Name"> string } | undefined;object?.metho">3()>;di><;di vdivclass="Nameexpressive-">44AEdeclare co61B0ob644A3F53ne644A3F53v64<4AE spans="tyle--0:#C5E478;--1:#3B">61B0st4AE >44AE <} } spans="tyle--0:#7FDBCA;--1:#09">6} } >4<4AE spans="tyle--0:#C5E478;--1:#3B">61B0undef4AE >3c3F53ob441111ne4<4AE. spans="tyle--0:#7FDBCA;--1:#09">6E72v4AE.>3;di><;di vdivclass="Nameexpressive-">44AEdeclare co61B0ob644A3F53ne6E<72?: spans="tyle--0:#C792EA;--1:#88">44A72?:>3F53v64<4AE spans="tyle--0:#C5E478;--1:#3B">61B0st4AE >44AE< } } spans="tyle--0:#D6DEEB;--1:#40">3 } }>c3F53ob4<4AE. spans="tyle--0:#7FDBCA;--1:#09">6E72ne4AE.>446E72v3;di>
This rule is not configurable.
If your project is still onboarding to TypeScript’s strictNullChecks compiler option, or more generally has unusual needs for null values, you might not receive false reports from this rule.
You might consider using Flint disable comments and/or configuration file disables for those specific situations instead of completely disabling this rule.