Skip to content

typescript/no-non-null-asserted-nullish-coalescing Restriction

What it does

Disallow non-null assertions in the left operand of a nullish coalescing operator.

Why is this bad?

The ?? nullish coalescing runtime operator allows providing a default value when dealing with null or undefined. Using a ! non-null assertion type operator in the left operand of a nullish coalescing operator is redundant, and likely a sign of programmer error or confusion over the two operators.

Example

ts
foo! ?? bar;

let x: string;
x! ?? "";

References

Released under the MIT License.