Skip to content

Bug: [no-duplicate-type-constituents] does not handle nested unions/intersections #9496

Closed
@abrahamguo

Description

@abrahamguo

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.5.2&fileType=.ts&code=C4TwDgpgBAGlC8UB2BXAtgIwgJygHygAoBnYbASyQHN9l0tsBKAbiA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Jge1oBNZjGyAQ3yJaRUrTIcmyfJXyxELVBkiJo0DtEjgwAXxB6gA&tsconfig=&tokens=false

Repro Code

type X = number | (string | number);

ESLint Config

module.exports = {
  parser: "@typescript-eslint/parser",
  rules: {
    "@typescript-eslint/no-duplicate-type-constituents": "error",
  },
};

tsconfig

{}

Expected Result

This code snippet does contain a duplicate type constituent. The rule does report it, but only if the parentheses (which are unnecessary) are removed.

Actual Result

The duplicate type constituent is not reported by the rule.

Additional Info

Reported by @auvred in #9479 (comment).

  • Do we care about this issue?
  • We'd need to implement a bit of recursion in order to account for this.
  • You can only get into this scenario if you have enabled this rule, you are not using ESLint Stylistic (with its no-extra-parens rule), and you are not using a formatter (like Prettier).
  • Are there similar cases with extraneous parentheses in other rules, and are they handled or not?

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions