Skip to content

Bug: [prefer-reduce-type-parameter] unfixable reporting #3440

Closed
@JounQin

Description

@JounQin
  • 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

{
  "rules": {
    "@typescript-eslint/<rule>": ["prefer-reduce-type-parameter"]
  }
}
// first case
export function normalizeParams<P>(params: P): P {
  return Object.entries(params).reduce((acc, [key, value]) => {
    value = typeof value === 'string' ? value.trim() : value;
    if (value) {
      acc[key as keyof P] = value;
    }
    return acc;
  }, {} as P);
}

// second case
export type Keys<T> = { [Key in keyof T]: Key };

export const toKeys = <T>(source: T): Keys<T> =>
  Object.keys(source).reduce((acc, k) => {
    const key = k as keyof T;
    acc[key] = key;
    return acc;
  }, {} as Keys<T>);

Expected Result

Ignore such cases

Actual Result

Error reporting

Additional Info

Versions

package version
@typescript-eslint/eslint-plugin 4.24.0
@typescript-eslint/parser 4.24.0
TypeScript 4.2.4
ESLint 7.27.9
node 12.22.1

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