Skip to main content
Module 4 · Lesson 2 of 28/22 in the course~16 min
Module lessons (2/2)

Types of Utilities

Lesson preview6 hands-on exercises readyCourse TypeScript · Module 4 — Utility Classes and Types

Derive secure DTOs and patches with Partial, Required, Readonly, Pick, Omit, Record, and Exclude.

What you'll learn in this lesson

  • Transform existing interfaces without duplicating them using Partial<T>, Required<T> and Readonly<T>.
  • Derive safe sub-contracts (e.g. DTO without id or without passwordHash) by combining Pick<T, K> and Omit<T, K>.
  • Model dictionaries typed with Record<K, V> and filter unions with Exclude<T, U> and Extract<T, U>.
  • Understand why Partial<T> and Readonly<T> operate only at the first level (shallow) and the particularity of Omit.

Overview

Handwriting User, UserUpdatePatch, PublicUser and UserCreateInput inevitably leads to forgetting a field as the model evolves. TypeScript's default Utility Types automatically calculate these derivatives from a single source of truth.

Using a union of literal keys as the first argument of Record<K, V> ensures that no configuration key can be forgotten.

Sections covered in this lesson

  1. 1Property modifiers: Partial, Required, Readonly
  2. 2Selection, Exclusion and Dictionaries: Pick, Omit, Record
  3. 3Guided practice
  4. 4Check for understanding
Pro Lesson · Module 4 — Utility Classes and Types

Unlock "Types of Utilities" and the full Course TypeScript curriculum

Derive secure DTOs and patches with Partial, Required, Readonly, Pick, Omit, Record, and Exclude.

Unlock all 6 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.

  • Instant access to all advanced modules in Course TypeScript plus 17 more courses
  • Hands-on browser exercises with automated test suites and solutions
  • 14-day money-back guarantee processed via Paddle.com

14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.