Type System
Generics Simulator
Generics are just type-level function parameters. Pick a concrete type below and watch it flow through the declaration.
Generic Function
identity takes a value of type T and returns the same type. When you call it, TypeScript replaces T with the argument's type — no information is lost.
Generic declaration
function identity<T>(value: T): T {
return value;
}T
After substitution
function identity<string>(value: string): string {
return value;
}Usage
const result = identity<string>("hello");
// result has type: string