What is a generic type?
Answer out loud or in your head first, then compare.
Answer
It's a way of writing a function or type that works with different kinds of data and keeps the information about their type. For example, a function that returns the first element of an array should return a user for an array of users and a number for an array of numbers.
A generic lets you describe that relationship instead of using any everywhere. It doesn't “guess” what came from an API, though. If I write the type of a fetch result myself without checking it, I can still mislead the program. Use generics where they explain the relationship between data, not where they complicate a simple function.
Why it matters: Helps you read and write library interfaces and shared functions.
Possible follow-ups: Why doesn't the generic in fetchJson<User>() check the JSON?
How did it go? Be honest — “Not yet” puts the question on your review list.
Related questions
- Generics — why a type parameter instead of any? — TypeScript
Further reading
- TypeScript for JavaScript Programmers(opens in a new tab)Accessed 22.10.2026. Type basics and their role while you work on code.