Skip to content

Bug: sort-type-union-intersection-members breaks code combining & and | #6158

@ysulyma

Description

@ysulyma

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=4.9.3&sourceType=module&code=C4TwDgpgBAglC8UDeUCGAuKAiGWDcUAvgFCiRQBCCyUARplhfkaeNAMLUoDGD7zJVuQAi1ABScAPpQCUUAGSw8xIA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6ZAe2jqNNtiaUOTWs3yJoyRGXxCRAW0TyARhNQZIE6F0jgwAXxD6gA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA

Repro Code

type A = { a: "A"; }
type B = { b: "B"; }
type C = { c: "C"; }

// this line violates @typescript-eslint/sort-type-union-intersection-members
export type D = (C | B) & A;

ESLint Config

{
  "extends": [
    "plugin:@typescript-eslint/recommended"
  ],
  "rules": {
    "@typescript-eslint/sort-type-union-intersection-members": "warn"
  }
}

tsconfig

{
  "compilerOptions": {
    // ...
  }
}

Expected Result

I expected that it would change the line to

export type D = A & (B | C);

Actual Result

It changed the line to

export type D = B | (A & C);

which has a different meaning from the original type.

Additional Info

No response

Versions

package version
@typescript-eslint/eslint-plugin 5.38.1
@typescript-eslint/parser 5.38.1
TypeScript 4.8.3
ESLint 8.24.0
node 16.17.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    duplicateThis issue or pull request already existspackage: 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

      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