Lesson 13 of 56 · Typescript
Utility Types – `Partial`, `Pick`, `Omit`, `Readonly`
Duration: 15 minutes
The Standard Library Utility Types
Partial<T> – make all properties optional
type User = { id: number; name: string; };
type UserUpdate = Partial<User>;
Pick<T, K> – select a subset of keys
type UserName = Pick<User, "name">; // { name: string }
Omit<T, K> – remove keys from a type
type UserNoId = Omit<User, "id">; // { name: string }
Readonly<T> – all properties become read‑only
type ReadonlyUser = Readonly<User>;
// readonly id: number; readonly name: string;
NonNullable<T> – exclude null and undefined
type MaybeString = string | null | undefined;
type DefinitelyString = NonNullable<MaybeString>; // string