avoid-unnecessary-type-params

Identify and remove TypeScript type parameters that appear only once.

Updated Jul 17, 2017
One-click install
npx skills add https://github.com/luyi985/lyi-bash --skill avoid-unnecessary-type-params
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: avoid-unnecessary-type-params
Source: https://github.com/luyi985/lyi-bash/tree/main/ai/skills/avoid-unnecessary-type-params
Command: npx skills add https://github.com/luyi985/lyi-bash --skill avoid-unnecessary-type-params

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Unnecessary type parameters clutter code and can degrade type inference, making maintenance harder and introducing confusion during reviews.

Core Features & Use Cases

  • Identify and remove type parameters that appear only once in functions, types, or classes.
  • Refactor generics to ensure parameters relate multiple types, improving readability and inference.
  • Review code for safer generics decisions during design and code reviews.

Quick Start

Review a TypeScript function that declares a generic parameter which only appears once and apply the rule to refactor it.

Frequently Asked Questions about avoid-unnecessary-type-params

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

FAQPage Schema
Why should I remove unnecessary type parameters from TypeScript generics?

Unnecessary type parameters clutter code and degrade type inference. Removing generics that appear only once improves readability, simplifies maintenance, and reduces confusion during TypeScript code reviews.

How do I identify unnecessary type parameters in TypeScript functions?

Check if a generic type parameter appears only once in a function, type, or class signature. If a parameter does not relate multiple types by appearing at least twice, it is unnecessary and should be refactored.

What is the best way to refactor generics to improve type inference?

Refactor generics by removing single-use type parameters and relying on TypeScript's built-in type inference. Ensure remaining parameters appear at least twice to properly relate types and improve overall readability.

When should a generic type parameter appear in a TypeScript signature?

A generic type parameter should appear at least twice in a TypeScript signature to relate multiple types. If it appears only once, it is unnecessary and should be removed to enforce safer generics decisions.

Can I use this refactoring rule for TypeScript class and type templates?

Yes, the rule applies to TypeScript function, type, and class templates. Any generic parameter that appears only once in these structures can be safely removed to improve readability and type inference.

Does removing single-use type parameters break existing TypeScript code?

Removing single-use type parameters is a safe refactoring practice. It streamlines type signatures without breaking existing logic, as the parameter does not relate multiple types and TypeScript can infer the type automatically.