TypeScript Generics, Explained Simply

Опубликовано: 09 Июнь 2026
на канале: Code on Principles
7
0

Generics look scary because of the angle brackets, but the idea is small: a generic is a type variable. It binds to whatever type you pass, and preserves that type all the way through, instead of throwing it away like any does.

This episode builds that intuition one step at a time:

• The problem: one near-identical function per type
• A type variable T: write it once, works for every type
• How T is inferred from the argument you pass
• Generics vs any: keeping the type versus losing it
• You already use generics (Array, Promise, Map)
• Constraints with T extends

Chapters
0:00 Write it once, not once per type
0:32 Make the type a variable
1:00 T is inferred from what you pass
1:20 any throws the type away
1:48 You already use generics
2:12 Two type variables
2:39 Constraints: demand a little
3:03 The mental model

The whole idea: write it once, keep the types, and let the caller fill in the blank.

Code on Principles makes beginner-friendly programming tutorials where the code, narration, and visuals move together. Small ideas, clearly seen.


На этой странице сайта вы можете посмотреть видео онлайн TypeScript Generics, Explained Simply длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь Code on Principles 09 Июнь 2026, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 7 раз и оно понравилось 0 зрителям. Приятного просмотра!