TypeScript Essentials

Lesson 07 · 11 min

Generics

One function, the type passes all the way through. Not abstraction for its own sake.

A generic is a type variable. You already use them: Promise<User>, Array<string>, Record<string, User>. Write your own when a function works with "anything" but you want to keep the concrete type on the way out. Handbook: Generics.

Sign in to continue

The rest of this lesson opens after sign up

The first lesson of every course is open without an account. To read on, solve the practice and use Ask, create a free account or log in.