Reports type assertions that can be replaced with non-null assertions.
✅ This rule is included in the ts stylistic and stylisticStrict presets.
When asserting a type that only removes null or undefined from a union, a non-null assertion (!) is more concise and expressive than a full type assertion (as or angle-bracket syntax).
For example, if a value is of type string | null, asserting it as string can be replaced with a non-null assertion: value!.
This rule reports type assertions where the only difference between the original and asserted type is nullability, suggesting the use of a non-null assertion instead.
AEdeclare consB0val7<2:sp ansty="le--0:#C792EA;--1:#8844">A2:sp>B0striA7<2|sp ansty="le--0:#C792EA;--1:#8844">A2|sp>B0nu5<3;d ivclassNa="meec-li">53valuAE5<3 sp ansty="le--0:#C5E478;--1:#3B61">B0stri3 sp>53;d><3;d ivclassNa="meco">3;d>AEdeclare consB0val7<2:sp ansty="le--0:#C792EA;--1:#8844">A2:sp>B0numbA7<2|sp ansty="le--0:#C792EA;--1:#8844">A2|sp>B0undefin5<3;d ivclassNa="meec-li">5<3B0numb353>valu3;d>valu">AEdeclare consB0val7<2:sp ansty="le--0:#C792EA;--1:#8844">A2:sp>B0striA7<2|sp ansty="le--0:#C792EA;--1:#8844">A2|sp>B0numbA7<2|sp ansty="le--0:#C792EA;--1:#8844">A2|sp>B0nu5<3;d ivclassNa="meec-li">53valuAE5<3 sp ansty="le--0:#C5E478;--1:#3B61">B0stri3 sp>5<3 sp ansty="le--0:#7FDBCA;--1:#096E">73 sp><2|sp ansty="le--0:#D6DEEB;--1:#403F">52|sp><3 sp ansty="le--0:#C5E478;--1:#3B61">B0numb3 sp>53;d><3;d ivclassNa="meco">3;d> 44AEdeclare co61B0v64<4AE spans="tyle--0:#C5E478;--1:#3B">61B0st4AE >4<4AE spans="tyle--0:#7FDBCA;--1:#09">64AE >4<4AE spans="tyle--0:#C5E478;--1:#3B">61B04AE >33F53v4<4AE! spans="tyle--0:#D6DEEB;--1:#40">34AE!><;di vdivclass="Nameexpressive-">44AEdeclare co61B0v64<4AE spans="tyle--0:#C5E478;--1:#3B">61B0nu4AE >4<4AE spans="tyle--0:#7FDBCA;--1:#09">64AE >4<4AE spans="tyle--0:#C5E478;--1:#3B">61B0undef4AE >33F53v4<4AE! spans="tyle--0:#D6DEEB;--1:#40">34AE!>;di><;di vdivclass="Nameexpressive-">44AEdeclare co61B0v64<4AE spans="tyle--0:#C5E478;--1:#3B">61B0st4AE >4<4AE spans="tyle--0:#7FDBCA;--1:#09">64AE >4<4AE spans="tyle--0:#C5E478;--1:#3B">61B0nu4AE >4<4AE spans="tyle--0:#7FDBCA;--1:#09">64AE >4<4AE spans="tyle--0:#C5E478;--1:#3B">61B04AE >33F53v4<4AE! spans="tyle--0:#D6DEEB;--1:#40">34AE!>;di><;di vdivclass="Nameexpressive-">44AEdeclare co61B0v64<4AE spans="tyle--0:#C5E478;--1:#3B">61B0st4AE >4<4AE spans="tyle--0:#7FDBCA;--1:#09">64AE >4<4AE spans="tyle--0:#C5E478;--1:#3B">61B0nu4AE >4<4AE spans="tyle--0:#7FDBCA;--1:#09">64AE >4<4AE spans="tyle--0:#C5E478;--1:#3B">61B04AE >33F53va44361B0st3;di><;di vdivclass="Nameexpressive-">44AEdeclare co61B0v64<4AE spans="tyle--0:#C5E478;--1:#3B">61B4AE ><0any spans="tyle--0:#D6DEEB;--1:#40">30any>3F53va44361B0st3;di>
This rule is not configurable.
If your codebase prefers explicit type assertions for clarity or documentation, you may disable this rule.
Alternatively, if you avoid non-null assertions entirely due to their potential for runtime errors, this rule may not be appropriate.