TypeScript
TypeScript GenericsTypeScript Generics
Generics act like variables for data types.
Read Time
5 min readDifficulty
BeginnerLast Updated
Jun 15, 2026Version
v1.0.0Introduction
Sometimes developers write functions that should work with numbers, strings, or arrays, but they still want strict safety. Generics allow you to pass a type into a function as an argument, just like you pass normal data into a function.
Example
Example
Key Points
- Generics use angle brackets like `
`. - The letter `T` stands for "Type".
- They make functions highly reusable without using the dangerous `any` type.
- TypeScript can usually infer the generic type automatically.