Skip to content

Bug: [no-unnecessary-type-parameters] False positive on curried functions #9721

@eranhirsch

Description

@eranhirsch

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=5.5.4&showAST=types&fileType=.ts&code=C4TwDgpgBAYg9nAPAFQDRQMoD4oF5NQQAewEAdgCYDOUARFXALYQBGcFItAsAFBRQB%2BKMkIly1OnDIBjCNz6C6wOABsK8-gC46zDVG1kIANwgAnANy9eFCNJUBDU9ABmAVxnAAllKjOEKLAAKCntge21kAEptRGxAuGAACzNtDEi8HHgkNEwsSx4gA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Jge1tiacTJTIAhtEK0ipWsRFCAtonyJoqDJCXQO0SODABfELqA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false

Repro Code

type Foo<T, S> = S extends "somebody"
  ? T extends "once"
  ? "told"
  : "me"
  : never;

declare function foo<T>(data: T): <S>(other: S) => Foo<T, S>;

ESLint Config

module.exports = {
  parser: "@typescript-eslint/parser",
  rules: {
    "@typescript-eslint/no-unnecessary-type-parameters": "error",
  },
};

tsconfig

No response

Expected Result

T shouldn't be surfaced by this rule; it has a meaningful usage in the type definitions.

Actual Result

T is surfaced as only being used once, incorrectly.

Additional Info

I maintain the Remeda typescript utility library. We rely heavily on curried functions, which are functions that return functions. The rule is firing for almost all our complex types where the type is passed on to the return type of the curried function. The non-curried functions, which are identical in terms of how the type param is used, are not falsely detected, so this has something to do with the param being passed on "through" to the return type of its returned function type.

When trying to reproduce this, I noticed that simpler cases where the T is used directly in the type aren't falsely detected; the issue can only be reproduced once we start introducing ternary conditions on other type params.

You can see a fuller example via the PR, which tries to introduce this rule into our codebase: remeda/remeda#801

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