Skip to content
This repository has been archived by the owner on Jan 19, 2019. It is now read-only.

Latest commit

 

History

History
35 lines (23 loc) · 815 Bytes

no-non-null-assertion.md

File metadata and controls

35 lines (23 loc) · 815 Bytes

Disallows non-null assertions using the ! postfix operator (no-non-null-assertion)

Rule Details

Using non-null assertions cancels the benefits of the strict null-checking mode.

Examples of incorrect code for this rule:

interface Foo {
    bar?: string;
}

const foo: Foo = getFoo();
const includesBaz: boolean = foo.bar!.includes("baz");

Examples of correct code for this rule:

interface Foo {
    bar?: string;
}

const foo: Foo = getFoo();
const includesBaz: boolean = foo.bar && foo.bar.includes("baz");

When Not To Use It

If you don't care about strict null-checking, then you will not need this rule.

Further Reading