Why generics
Generics let one implementation preserve the type supplied by its caller. They are safer than any because the relationship between input and output is retained.
TypeScript
function first<T>(values: T[]): T | undefined { return values[0]; } const name = first(["Ada", "Lin"]);
Constraints
A constraint states the minimum shape a generic value must have. For example, T extends { id: number } permits code to use id while allowing richer objects.
Did you know my courses are all printer-friendly? This means you can easily export them to PDF or print them for later use.
