Skip to content

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

@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

      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