Generics create reusable types that work with different types:
function first<T>(arr: T[]): T | undefined {
return arr[0];
}
const num = first([1, 2, 3]); // num: number
const str = first(["a", "b"]); // str: string
The <T> is a type parameter that gets filled in when you call the function.