Skip to content

[consistent-indexed-object-style] fixer produces invalid code and deletes comments #4730

Closed
@Josh-Cena

Description

@Josh-Cena
  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have read the FAQ and my problem is not listed.

Repro

Playground

{
  "rules": {
    "@typescript-eslint/consistent-indexed-object-style": ["error", "index-signature"]
  }
}
type NavbarItems = Record<
  string,
  // lazy-load the component
  () => (props: any) => JSX.Element
>;

type NavbarItems = Record<
  Exclude<"a" | "b" | "c", "a">,
  string
>;

Expected Result

I expect the first to be fixed with comment preserved, and the second to be fixed to valid code:

// lazy-load the component
type NavbarItems = { [key: string]: () => (props: any) => JSX.Element };

type NavbarItems = { [key in Exclude<"a" | "b" | "c", "a">]: string };

Actual Result

// This has the comment swallowed
type NavbarItems = { [key: string]: () => (props: any) => JSX.Element };

// This should use mapped type instead of index signature
type NavbarItems = { [key: Exclude<"a" | "b" | "c", "a">]: string };

Additional Info

Versions

package version
@typescript-eslint/eslint-plugin 5.16.0
@typescript-eslint/parser 5.16.0
TypeScript 4.6.3
ESLint 8.11.0
node 17.5.0

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