consecutiveNonNullAssertions
Reports unnecessary extra non-null assertions.
✅ This rule is included in the ts logical
preset.
The non-null assertion operator (!
) is used to assert that a value is not null or undefined.
Using it multiple times in a row does not do anything, and just takes up space unnecessarily.
Examples
Section titled “Examples”declare const value: string | null;
value!!.toUpperCase();
declare const value: string | null;
value!.toUpperCase();
Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”There are no situations where it is beneficial to include extra chains of !!
s.
Equivalents in Other Linters
Section titled “Equivalents in Other Linters”
Made with ❤️🔥 in Boston by
Josh Goldberg and contributors.