avoid-unnecessary-type-params

Detects and eliminates unnecessary TypeScript type parameters in generic functions and classes.

Updated Sep 5, 2026
One-click install
npx skills add https://github.com/pohlai88/afenda-xforge-v5 --skill avoid-unnecessary-type-params-pohlai88
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: avoid-unnecessary-type-params
Source: https://github.com/pohlai88/afenda-xforge-v5/tree/main/.agents/skills/avoid-unnecessary-type-params
Command: npx skills add https://github.com/pohlai88/afenda-xforge-v5 --skill avoid-unnecessary-type-params-pohlai88

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? TypeScript code often accumulates unnecessary generic type parameters that appear only once in a signature, creating a false sense of type safety and degrading type inference. This Skill helps you identify and remove these superfluous generics so your types actually relate values to each other. ## Core Features & Use Cases - Golden Rule Detection: Applies the rule that type parameters must appear twice or more to establish a relationship, flagging single-use generics like return-only parseYAML<T>(input: string): T. - Simplification Guidance: Shows how to replace unnecessary generics with unknown, concrete types, or explicit type assertions while preserving real type relationships like getProperty<T, K extends keyof T>(obj: T, key: K): T[K]. - Class Generic Review: Identifies class-level type parameters used in only one method and recommends moving them to the method or using concrete types. - Use Case: While reviewing a utility library, you find function third<A, B, C>(a: A, b: B, c: C): C. The Skill flags A and B as single-use and guides you to rewrite it as function third<C>(a: unknown, b: unknown, c: C): C. ## Quick Start Review this TypeScript function signature and tell me whether its type parameters are necessary, then simplify any generics that appear only once.

Frequently Asked Questions about avoid-unnecessary-type-params

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I know if a TypeScript generic type parameter is unnecessary?

A type parameter is unnecessary if it appears only once in the signature besides its declaration. Generics exist to relate types, so a parameter like T in `function f<T>(x: string): T` relates nothing and is equivalent to using `any`.

Why are return-only generics in TypeScript dangerous?

Return-only generics like `parseYAML<T>(input: string): T` act as hidden type assertions, letting any assignment compile without validation. Returning `unknown` instead forces callers to use explicit assertions or type guards, making the unsafety visible.

When should I use generics in TypeScript functions?

Use generics when the type parameter appears at least twice and relates multiple types, such as `identity<T>(arg: T): T` or `getProperty<T, K extends keyof T>(obj: T, key: K): T[K]`. If it appears once, use `unknown` or a concrete type.

Should a TypeScript class be generic if only one method uses the type?

No. If a class type parameter is used in only one method, move the generic to that method or use a concrete union type instead. Often a standalone function is simpler than a generic class with a single-use parameter.

Do unnecessary type parameters affect TypeScript type inference?

Yes. Superfluous generics can make inference less successful because the compiler must resolve parameters that carry no relational information. Removing them produces cleaner signatures and more predictable inferred types.