Skip to content

Latest commit

 

History

History
38 lines (26 loc) · 1.12 KB

no-non-null-asserted-nullish-coalescing.md

File metadata and controls

38 lines (26 loc) · 1.12 KB

Disallows using a non-null assertion in the left operand of the nullish coalescing operator (no-non-null-asserted-nullish-coalescing)

Rule Details

The nullish coalescing operator is designed to provide a default value when dealing with null or undefined. Using non-null assertions in the left operand of the nullish coalescing operator is redundant.

Examples of incorrect code for this rule:

/* eslint @typescript-eslint/no-non-null-asserted-nullish-coalescing: "error" */

foo! ?? bar;
foo.bazz! ?? bar;
foo!.bazz! ?? bar;
foo()! ?? bar;

Examples of correct code for this rule:

/* eslint @typescript-eslint/no-non-null-asserted-nullish-coalescing: "error" */

foo ?? bar;
foo ?? bar!;
foo!.bazz ?? bar;
foo!.bazz ?? bar!;
foo() ?? bar;

When Not To Use It

If you are not using TypeScript 3.7 (or greater), then you will not need to use this rule, as the operator is not supported.

Further Reading