Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
4 tasks done
maennchen opened this issue Nov 8, 2022 · 1 comment · Fixed by #5997
Closed
4 tasks done
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@maennchen
Copy link

maennchen commented Nov 8, 2022

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
@maennchen maennchen added bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels Nov 8, 2022
@Josh-Cena Josh-Cena added accepting prs Go ahead, send a pull request that resolves this issue and removed triage Waiting for team members to take a look labels Nov 11, 2022
@Josh-Cena
Copy link
Member

Fun, welcoming PRs.

mhnaeem added a commit to mhnaeem/typescript-eslint that referenced this issue Nov 16, 2022
Array type with intersection that has parentheses does not retain the parens.
typescript-eslint#5941
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants