Skip to content

Bug: [no-unnecessary-type-conversion] a locally-redefined String/Number/Boolean/BigInt is treated as the global builtin #12522

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=GYVwdgxgLglg9mABAZSgJxmA5gCgB4BciAzuplgJSIDeAUIomgKZQhpJ4DctAvrbaEiwEiYHDg5iRUhmxU6DZq3Yoy2SRW48gA&eslintrc=N4KABGBEAOCGBOBnApvSAuKABALgT2mUQGN4BLaHAWiIBsyA7HAejiVUgBpwo2V4A8pTIB7BogxhQECDHgiAVsmI5JkAHTMcJMQDMyAc3ULEYyDwC%2B3WfACutIpOkzIuAkVIVqdRiwYiqWwYGZSJEBDwqfEIqYjEAN1REUQY1VHk0SxALIA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eFYDAruuGAL4g9A&tokens=false

Repro Code

function String(x: string) {
  return x;
}

function foo(s: string) {
  return String(s);
}

ESLint Config

module.exports = {
  parser: "@typescript-eslint/parser",
  parserOptions: {
    project: "./tsconfig.json",
  },
  rules: {
    "@typescript-eslint/no-unnecessary-type-conversion": "error",
  },
};

tsconfig

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

Expected Result

no error

Actual Result

Passing a string to String() does not change the type or value of the string

and the "Remove the type conversion." suggestion rewrites String(s) to s, which changes what the code does

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