generics-as-functions

Installation
SKILL.md

Think of Generics as Functions Between Types

Overview

Generic types are the type-level equivalent of functions in value space. Just as a function takes parameters and returns a value, a generic type takes type parameters and produces a concrete type. This mental model helps you write better generic types by applying the same principles you use for writing functions: constraining inputs, choosing good names, and documenting behavior.

Understanding generics as functions between types clarifies when to use constraints, how to name type parameters, and why some generic patterns work while others don't. This perspective is essential for effective type-level programming in TypeScript.

When to Use This Skill

  • Defining generic types that transform other types
  • Writing generic functions with type parameters
  • Constraining what types can be passed to generics
  • Documenting generic types with TSDoc
  • Creating reusable type utilities

The Iron Rule

Think of generic types as functions between types: use extends to constrain inputs like type annotations, choose descriptive names, and document with @template TSDoc.

Related skills
Installs
9
GitHub Stars
2
First Seen
Feb 3, 2026