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

Utility types

TypeScript ships with built-in utility types that transform one type into another. Instead of writing near-duplicate interfaces by hand, you derive them, and they stay in sync automatically when the original changes.

We'll use this User type throughout:

ts
interface User {
  id: number;
  name: string;
  email: string;
  password: string;
  role: 'admin' | 'member';
}

Partial<T> and Required<T>

Partial makes every property optional, which is perfect for updates:

TypeScript · editable

Pick<T, Keys> and Omit<T, Keys>

Select or remove properties:

TypeScript · editable

Omit<User, 'password'> for API responses is a real-world security pattern: the compiler stops you from sending password hashes to clients.

Readonly<T>

TypeScript · editable

Record<Keys, Value>

Build an object type from a set of keys:

TypeScript · editable

Working with functions: ReturnType, Parameters, Awaited

Extract types from existing functions, which is handy when a library doesn't export the types you need:

TypeScript · editable

Working with unions: Exclude, Extract, NonNullable

TypeScript · editable

Cheat sheet

Utility Does
Partial<T> All properties optional
Required<T> All properties required
Readonly<T> All properties read-only
Pick<T, K> Only keys K
Omit<T, K> All except keys K
Record<K, V> An object with keys K and values V
Exclude<U, X> / Extract<U, X> Remove / keep union members
NonNullable<T> Remove null and undefined
ReturnType<F> / Parameters<F> A function's return / parameter types
Awaited<T> Unwrap a Promise

Practice

Given the Product type, derive (don't rewrite!) these:

  1. ProductInput: what a form submits (no id, createdAt or rating).
  2. ProductPatch: an update where any field except id is optional, and id is required.
  3. ProductCard: just name, price and imageUrl, all read-only.
TypeScript · editable
✎ Check your understanding

1.Which utility type creates a type with every property optional?

2.Why prefer Omit<User, 'password'> over writing a separate PublicUser interface by hand?

← Generics