Generics are a TypeScript feature that allows us to pass in various types of data and create reusable code to handle different inputs. They allow us to define placeholder types which are then replaced when the code is executed with the actual types passed in.
Generics are like a template that can be reused across the same piece of code multiple times but with the value being independent of each invocation of the function.
This might seem like a slightly complex topic at first, but the good news is when you're just starting out, you'll mostly use generic functions or interfaces created by others. That could be the TypeScript team or developers of third-party libraries.
In most cases, you won’t have to write your own generics right away. You just need to remember one key idea:
Every time you see those funny-looking angle brackets (< >), think “generics.”
They’re just placeholders for types!
First, I want you to observe this piece of code.

You'll notice that the type changes (we can pass string, number, boolean, or even our own type), but one thing remains consistent:
We always get back an array—no matter what type we pass.

This means we’re not switching between number[], string[], or boolean[] manually.
We just pass the type we want, and it automatically returns an array of that type.
Right-click on the code and select “Go to type definition.”

This lets you inspect the generic definition and see how the type is flowing through the interface.
