Search code examples
typescripteslinttypescript-eslint

Why does the "no-unnecessary-conditions" rule get confused by "!!"?


When adding the @typescript-eslint/no-unneccessary-conditions rule, we are getting many errors on code which appears correct.

The error message seems to be incorrect too.

What am I missing?

type Foo = { foo: string }

export function myFunction(nullableThing: Foo | null) {
  if (!!nullableThing) { // <-- "Unnecessary conditional, value is always falsy"
    return 'foo'
  } else {
    return 'bar'
  }
}

Solution

  • This was fixed as suggested by the comments - restarting the VS Code ESLint server