Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Bug: [no-unnecessary-type-parameters] Type parameters that use other type parameters and get only used once are often not unnecessary #11395

Closed as not planned
Labels
bugSomething isn't workingpackage: eslint-pluginIssues related to @typescript-eslint/eslint-pluginworking as intendedIssues that are closed as they are working as intended
@TheBlue-1

Description

@TheBlue-1

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 havesearched for related issues and found none that matched my issue.
  • I haveread the FAQ and my problem is not listed.

Playground Link

playground link

Repro Code

/** uses a fallback when a value is not set on an object */functionnotSetFallback<T,Kextendsstring,// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters -- removing this changes the return typeOextends(Partial<Record<K,T>>&Record<string,unknown>)|undefined>(obj:O,key:K,fallback:T):T|undefined{returnobj&&keyinobj ?obj[key] :fallback;}functionnotSetFallbackWithoutObjectType<T,Kextendsstring>(obj:(Partial<Record<K,T>>&Record<string,unknown>)|undefined,key:K,fallback:T):T|undefined{returnobj&&keyinobj ?obj[key] :fallback;}functiontester(fallbackString:string){notSetFallback({a:true,b:"hi"},"b",fallbackString);// oknotSetFallbackWithoutObjectType({a:true,b:"hi"},"b",fallbackString);// errorconstobj={a:true,b:"hi"}asPartial<{a:boolean,b:string}>conststringValue1:string|undefined=notSetFallback(obj,"b",fallbackString);// okconststringValue2:string|undefined=notSetFallbackWithoutObjectType(obj,"b",fallbackString);// error (return value typed "string | boolean | undefined")}

ESLint Config

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

tsconfig

{"compilerOptions": {"strictNullChecks":true  }}

Expected Result

I would expect the rule not to report cases where the type parameter is not unncecesarry like here.

I am not sure if that covers it but probably i would not expect the rule to not report a type parameter that uses another type parameter that is used at least twice in the function declaration.

Actual Result

The rule reported the type parameter to be unnecessary although it did change the behaviour of the function and also change the return type.

Additional Info

No response

edited:
Partial<Record<K, T>> to(Partial<Record<K, T>> & Record<string, unknown>)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpackage: eslint-pluginIssues related to @typescript-eslint/eslint-pluginworking as intendedIssues that are closed as they are working as intended

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp