Skip to content

Configs: [prefer-nullish-coalescing] change default for ignoreConditionalTests to true #8243

Closed
@bradzacher

Description

@bradzacher

Before You File a Proposal Please Confirm You Have Done The Following...

Description

Ref: #7955

IMO most codebases would prefer to avoid nullish coalescing in conditional tests.

Consider the downlevelled output:

if (x || y) { }

// vs

if (x ?? y) { } 
// downlevelled to
if (x != null ? x : y) { }

There's an extra check there that doesn't do anything.

The logic behind the latter is much harder to grasp exactly, IMO:

  • If x is truthy, then true,
  • If x is falsey and not nullish, then false,
  • Else the boolean coercion of y

vs the former:

  • If x is falsey then false
  • Else the boolean coercion of y

It's just A lot simpler to read and understand the non-nullish-coalescing form, IMO.

Impacted Configurations

No response

Additional Info

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issuebreaking changeThis change will require a new major version to be releasedlocked due to agePlease open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.package: eslint-pluginIssues related to @typescript-eslint/eslint-pluginpreset config changeProposal for an addition, removal, or general change to a preset config

    Type

    No type

    Projects

    No projects

    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