Skip to content

[strict-boolean-expressions] Destructuring with default assignment leads to false positive #708

Closed
@novemberborn

Description

@novemberborn

I have an object with an optional boolean field. It's passed to a function. I destructure the field, assigning false if it's undefined. I then combine it with the ! operator in an if-condition. The rule complains about an unexpected non-boolean.

Repro

{
  "rules": {
    "@typescript-eslint/strict-boolean-expressions": "error"
  }
}
type Options = { field?: boolean }

function validate({ field = false }: Options) {
  if (!field) {
    // …
  }
}

(To be fair the type of the function argument is inferred, but that's harder to express in a repro.)

Expected Result

No linter errors.

Actual Result

The rule complains that field is a non-boolean.

Versions

package version
@typescript-eslint/eslint-plugin 1.12.0
@typescript-eslint/parser 1.12.0
TypeScript 3.5.3
ESLint 6.0.1
node X.Y.Z
npm X.Y.Z

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions