Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[strict-boolean-expressions] False positive with union types having only one falsey value #3115

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

Closed
3 tasks done
tkalliom opened this issue Feb 26, 2021 · 0 comments · Fixed by #3236
Closed
3 tasks done
Labels
bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@tkalliom
Copy link

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have read the FAQ and my problem is not listed.

Repro

module.exports = {
    "root": true,
    "parser": "@typescript-eslint/parser",
    "parserOptions": {
        "tsconfigRootDir": __dirname,
        "project": ["./tsconfig.json"]
    },
    "plugins": ["@typescript-eslint"],
    "rules": {
        "@typescript-eslint/strict-boolean-expressions": ["error"]
    }
}
function f(arg: "Option1" | "Option2" | null) {
    if (arg)
        console.log(`Input: ${arg}`);
    else
        console.log("Null was input");
}

tsconfig: the default as output by tsc --init

Expected Result

I expected there to be no error, as there is exactly one possible falsey value, no ambiguity.

Actual Result

  2:9  error  Unexpected nullable string value in conditional. Please handle the nullish/empty cases explicitly  @typescript-eslint/strict-boolean-expressions

Additional Info
This is similar to the likely non-bug #2894, but in that example there are multiple falsey values.

Versions

package version
@typescript-eslint/eslint-plugin 4.15.2
@typescript-eslint/parser 4.15.2
TypeScript 4.1.5
ESLint 7.20.0
node 10.24.0
@tkalliom tkalliom added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels Feb 26, 2021
@bradzacher bradzacher added bug Something isn't working and removed triage Waiting for team members to take a look labels Feb 26, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 6, 2021
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
2 participants