Module lessons (2/2)
Types of Utilities
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>andReadonly<T>. - Derive safe sub-contracts (e.g. DTO without
idor withoutpasswordHash) by combiningPick<T, K>andOmit<T, K>. - Model dictionaries typed with
Record<K, V>and filter unions withExclude<T, U>andExtract<T, U>. - Understand why
Partial<T>andReadonly<T>operate only at the first level (shallow) and the particularity ofOmit.
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
- 1Property modifiers:
Partial,Required,Readonly - 2Selection, Exclusion and Dictionaries:
Pick,Omit,Record - 3Guided practice
- 4Check for understanding
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.