Learn to Code
All tracks
Learn to Code

Free lessons from scratch to pro — every language, databases and DevOps.

AboutContactPrivacy PolicyTerms of Use

Your progress is saved in this browser. © 2026 Learn to Code

TS
TypeScript
0/10 completed
Beginner
Why TypeScript?Basic types and inferenceTyping functionsObjects, interfaces and type aliases
Intermediate
Unions and narrowingLiteral types, tuples and enumsGenerics
Advanced
Utility typesMapped and conditional types
Pro
TypeScript in real projects
Tracks / TypeScript / Advanced

Mapped and conditional types

Utility types like Partial and Pick aren't magic. They're written in TypeScript itself using mapped and conditional types. Learning these lets you build your own type tools, and read the type definitions of any library.

keyof and indexed access (recap)

TypeScript · editable

typeof: get a type from a value

TypeScript · editable

Mapped types: transform every property

A mapped type loops over keys with [K in Keys]:

TypeScript · editable

The as clause renames keys, using template literal types.

Conditional types: T extends U ? X : Y

A type-level if:

TypeScript · editable

infer: extract part of a type

infer declares a type variable that captures part of the matched type. This is how ReturnType and Awaited are built:

TypeScript · editable

Distributive conditional types

When T is a union, conditional types apply to each member separately:

TypeScript · editable

Putting it together: a type-safe event emitter

TypeScript · editable

Libraries like tRPC, Zod, Prisma and React Hook Form use exactly these techniques to give you end-to-end type safety.

Keep it readable. Advanced types are powerful, but your teammates must understand them. Prefer simple types in application code, and save the clever ones for shared libraries.

Practice

  1. Write Nullable<T>, which makes every property of T accept null too.
  2. Write FunctionKeys<T>, the keys of T whose values are functions. (Hint: a mapped type with as plus a conditional type; key remapping to never removes a key.)
TypeScript · editable
✎ Check your understanding

1.What does { [K in keyof T]?: T[K] } produce?

2.In T extends Promise<infer V> ? V : T, what does infer V do?

← Utility types