Use a type parameter for reusable function typing.
Section: Generics
Generic identity function
typescript
typescript
function identity<T>(value: T): T {
return value;
}Explanation
Generics let a function preserve type information across inputs and outputs.
Learn the surrounding workflow
Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.
Related commands
Same sheet · prioritizing Generics
Generic array helper
Write array helpers that preserve element types.
Constrain generic types
Require a minimum shape for a type parameter.
Constrain a key parameter with `keyof`
Accept only valid property names for a given object type.