Skip to content

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

@tkalliom

Description

@tkalliom
  • 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

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

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy