Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
novemberborn opened this issue Jul 16, 2019 · 1 comment
Labels
bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@novemberborn
Copy link

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
@novemberborn novemberborn added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look labels Jul 16, 2019
@j-f1 j-f1 added bug Something isn't working and removed triage Waiting for maintainers to take a look labels Jul 16, 2019
@bradzacher
Copy link
Member

this no longer repros in master, I think it was fixed in #794

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

No branches or pull requests

3 participants