Skip to content

Latest commit

 

History

History
45 lines (29 loc) · 894 Bytes

no-non-null-assertion.md

File metadata and controls

45 lines (29 loc) · 894 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 code for this rule:

❌ Incorrect

interface Foo {
  bar?: string;
}

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

✅ Correct

interface Foo {
  bar?: string;
}

const foo: Foo = getFoo();
const includesBaz: boolean = foo.bar?.includes('baz') ?? false;

When Not To Use It

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

Further Reading

Attributes

  • ✅ Recommended
  • 🔧 Fixable
  • 💭 Requires type information