Skip to content

Bug: [prefer-nullish-coalescing] a Boolean redefined in an outer scope is treated as the global builtin #12524

Description

@zaewc

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have searched for related issues and found none that matched my issue.
  • I have read the FAQ and my problem is not listed.
  • If I used AI assistance to prepare this issue, I have reviewed and followed the AI Contribution Policy.

Playground Link

https://typescript-eslint.io/play/#ts=6.0.3&fileType=.tsx&code=GYVwdgxgLglg9mABHEUCmAnAFASkQbwChFEIEBnKRAITjgBs0BDJAXkSwA8AuRcAazBwA7mDysAfIk4BuQsUQY0UEBiRYmvShhhgA5ogA%2BiMCHr0ANIgBGWqDv3iptBszAajx6zjkBfIA&eslintrc=N4KABGBEAOCGBOBnApvSAuKABALgT2mUQGN4BLaHAWiIBsyA7HAejiVUgBpwo2V4A8pTIB7BogxhQECDHgiAVsmI5JkAHTMcJMQDMyAc3ULEYyDwC%2B3WfACutIpOkzIuAkVIVqdRi2jxkXVQqBnt6RAALKmIRWAcSRgNJAG0eGShUeTRrdKkwNNzIQwYRAIAhEREHWAYAYRFUYlEGSRw7ZAKICwKAXUsQbpAgA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false

Repro Code

function outer() {
  const Boolean = (x: unknown) => x;

  return (a: string | null, b: string) => Boolean(a || b);
}

ESLint Config

module.exports = {
  parser: "@typescript-eslint/parser",
  parserOptions: {
    project: "./tsconfig.json",
  },
  rules: {
    "@typescript-eslint/prefer-nullish-coalescing": ["error", { ignoreBooleanCoercion: true }],
  },
};

tsconfig

{
  "compilerOptions": {
    "strict": true
  }
}

Expected Result

a || b should be flagged (suggesting a ?? b). The wrapping Boolean is a local function, not the global Boolean, so ignoreBooleanCoercion shouldn't apply here.

Actual Result

no error

Additional Info

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issuebugSomething 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