Skip to content

Bug: [array-type] --fix removes neccesary brackets leading to a type with a different meaning #5941

Closed
@maennchen

Description

@maennchen

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.8.4&jsx=true&sourceType=module&code=C4TwDgpgBA6g9gJwNYEsB2BzAgghBDEKAXigG8AoKKOAV2AgQAUE5IFQAuKHfEAHkpUyUdGgbNWDUAHkxXAM7AE6DFAC+UAGTDR4lm1AAVAO5wFSlesEA+ANzk198qEhQAQiyQQ0PAsTKCtPRM+lIgXL78glQAFKQiaGIhkuwgshDmypjqWjqJeilGppmWagCUNvaO5EA&eslintrc=N4KABGBEAOA2CuBzAlgOwM6QFxgNrgigAEAXAT2gFN0BjAJ2WhIFprY0TICBdAGgMiUAHiUqoAJphz5CUOEjRZSFavUYs2HAPToSDGpx78IMAIZ10lOtmLkqtBk1bp2qElujnL141DrxYahtQWUhlezUnTTctczpTMmY7ShtBOjoAe2sCAF8QHKA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA

Repro Code

type WorkingArray = {
  outerProperty: Array<
    { innerPropertyOne: string } & { innerPropertyTwo: string }
  >;
};

type BrokenArray = {
  outerProperty: Array<
    ({ innerPropertyOne: string } & { innerPropertyTwo: string })
  >;
};

ESLint Config

module.exports = {
  plugins: ["@typescript-eslint"],
  extends: ["plugin:@typescript-eslint/strict"],
  parser: "@typescript-eslint/parser",
  parserOptions: {
    tsconfigRootDir: __dirname,
    project: ["./tsconfig.json"],
    ecmaVersion: "latest",
  },
};

tsconfig

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

Expected Result

interface WorkingArray {
  outerProperty: ({ innerPropertyOne: string } & { innerPropertyTwo: string })[];
}

interface BrokenArray {
  outerProperty: ({ innerPropertyOne: string } & { innerPropertyTwo: string })[];
}

Actual Result

interface WorkingArray {
  outerProperty: ({ innerPropertyOne: string } & { innerPropertyTwo: string })[];
}

interface BrokenArray {
  outerProperty: { innerPropertyOne: string } & { innerPropertyTwo: string }[];
}
6c6
<   outerProperty: { innerPropertyOne: string } & { innerPropertyTwo: string }[];
---
>   outerProperty: ({ innerPropertyOne: string } & { innerPropertyTwo: string })[];

The meaning of the BrokenArray type should not be changed.

Additional Info

No response

Versions

package version
@typescript-eslint/eslint-plugin 5.42.1
@typescript-eslint/parser 5.42.1
TypeScript 4.8.4
ESLint 8.27.0
node 18.7.0

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