Skip to content

Latest commit

 

History

History
59 lines (44 loc) · 804 Bytes

no-extra-non-null-assertion.md

File metadata and controls

59 lines (44 loc) · 804 Bytes

Disallow extra non-null assertion (no-extra-non-null-assertion)

Rule Details

Examples of code for this rule:

❌ Incorrect

const foo: { bar: number } | null = null;
const bar = foo!!!.bar;
function foo(bar: number | undefined) {
  const bar: number = bar!!!;
}
function foo(bar?: { n: number }) {
  return bar!?.n;
}

✅ Correct

const foo: { bar: number } | null = null;
const bar = foo!.bar;
function foo(bar: number | undefined) {
  const bar: number = bar!;
}
function foo(bar?: { n: number }) {
  return bar?.n;
}

How to Use

{
  "@typescript-eslint/no-extra-non-null-assertion": ["error"]
}

Attributes

  • ✅ Recommended
  • 🔧 Fixable
  • 💭 Requires type information