Skip to content

Bug: [no-unnecessary-type-conversion] rule conflicts with no-unsafe-enum-comparison #11472

@davidhouweling

Description

@davidhouweling

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.

Playground Link

https://typescript-eslint.io/play/#ts=5.9.2&fileType=.tsx&code=LAKAxg9gdgzgLgAjAV3hAtgSQCYILwIDkAltgIyEDcooAplMuggMKpwY4wIDeoCCOMviKkKAGj4DsAJmEkZhCSAC%2BNcNHhIMABwCGAJ1oA5CABUIAZTj7iUAObCUaLLjxuWbDthgA6QdXVYREh0PUMAdWI4AAtzKxt7R08XfHdWZ04-ch92eNs7AAoASgCgA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Jge1tiacTJTIAhtEK0ipWmQ5MAbomjJKM9FAXQO0SABpw2PBPJUa9ZIxbsuPYQDNE9JrAC2Ujk%2BIjKyFRkjrNkHoAviBBQA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false

Repro Code

const customId = 'id1';

enum CustomIds {
  Id1 = 'id1',
  Id2 = 'id2',
}

const compareNoToString = customId === CustomIds.Id1;
const compareWithToString = customId === CustomIds.Id1.toString();

ESLint Config

module.exports = {
  parser: "@typescript-eslint/parser",
  rules: {
    "@typescript-eslint/no-unnecessary-type-conversion": "error",
    "@typescript-eslint/no-unsafe-enum-comparison": "error"
  },
};

tsconfig

{
  "compilerOptions": {
    "strictNullChecks": true
  }
}

Expected Result

No collision with rules...

Actual Result

Line 9 shows what happens when you do not include .toString() resulting in @typescript-eslint/no-unsafe-enum-comparison throwing...
Line 10 shows what happens when you do add .toString() to resolve the issue on line 9... resulting in @typescript-eslint/no-unnecessary-type-conversion throwing, which it wants the code from line 9.

Additional Info

Last week #11374 added @typescript-eslint/no-unnecessary-type-conversion to strict checks, which has resulted in a failure to build (dependabot) as I have @typescript-eslint/no-unsafe-enum-comparison set to error in my eslint config already.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugintriageWaiting for team members to take a look

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions