Generics
Write one function, class or type that works for many types and keeps the exact type: type parameters, constraints, defaults, inference control and variance.
A generic is a template with a blank in it. You write the code once, leave a blank for the type, and each caller fills the blank in. A function that returns the first item of an array should work for numbers, text and users, and it should tell you which one you got. Without generics you must pick between copying the code for every type or giving up the types with any.
This phase starts with the problem generics solve, then builds up: type parameters and inference, constraints ("any type, as long as it has a length"), generic interfaces, aliases and classes, real patterns (a typed fetchJson, an event emitter, a cache, groupBy), ways to steer inference when the compiler guesses wrong, and finally variance: why an array of dogs is not quite an array of animals.
Every example is checked by the real TypeScript compiler. Use the // ^? lines and the Types panel often: with generics, seeing what the compiler worked out is half the lesson.
Practise this phase
Hands-on exercises: write the code, see your page live, and press Check to have it tested automatically.