Partial / Required / Pick / Omit
Partial, Required, Pick, and Omit are built-in mapped types that reshape an object type: make every field optional or required, or keep or drop a set of keys.
Detailed Explanation
These four utilities are the everyday object tools. They all take an object type and return another object type. None of them allocate a value.
Partial<T> makes every property optional. A function that updates a user from a form takes Partial<User> so the caller can send only email. Reads of those properties then include undefined, which is the truth: the field may be missing.
Required<T> is the inverse. It removes the optional modifier from every property. Use it when you have a draft type and a later step that fills every field. It does not remove | undefined from a property whose value type includes undefined; it only strips ?.
Pick<T, K> keeps the listed keys. K must be keyof T (or a union of those keys). Pick<User, "id" | "email"> is a smaller object type with just those two fields, including their optionality and readonly modifiers.
Omit<T, K> drops the listed keys. It is Pick<T, Exclude<keyof T, K>>. Use it to hide a field from a public DTO (Omit<User, "passwordHash">) or to replace a field by omitting it and intersecting a new one: Omit<User, "id"> & { id: number }.
Readonly<T> belongs in the same family and is covered under readonly. Record<K, V> is adjacent and is covered under data structures: it builds an object type from a key union rather than transforming an existing one.
Two design notes. First, all four are shallow. Partial<User> does not make nested address fields optional. Deep variants are a few lines of mapped type, or a library, and they have costs in compile time. Second, Omit on a type with an index signature can surprise you: dropping a known key leaves the index signature, so extra keys may still be allowed.
At public APIs, alias the result. type UserUpdate = Partial<Pick<User, "email" | "displayName">> is a contract you can document. Inlining Partial<Pick<...>> at every call site makes errors longer and invites copy-paste drift.
These utilities do not validate objects at runtime. A Partial<User> annotation on req.body still accepts anything any hands it. Pair the type with a runtime check at the boundary.
Code Examples
1. Partial for an update payload.
// 1. Partial for an update payload.
type User = {
id: string;
email: string;
displayName?: string;
};
type UserUpdate = Partial<Pick<User, "email" | "displayName">>;
function updateUser(id: string, patch: UserUpdate): void {
console.log(id, patch.email);
}
updateUser("u1", { email: "ada@example.com" });2. Pick and Omit for a public DTO.
// 2. Pick and Omit for a public DTO.
type UserRow = User & { passwordHash: string };
type PublicUser = Omit<UserRow, "passwordHash">;
type UserPreview = Pick<User, "id" | "displayName">;
const preview: UserPreview = { id: "u1", displayName: "Ada" };3. Required fills in optionals; replacing a field uses Omit plus intersection.
// 3. Required fills in optionals; replacing a field uses Omit plus intersection.
type Draft = { id?: string; email?: string };
type Saved = Required<Draft>;
const saved: Saved = { id: "u1", email: "ada@example.com" };
type UserWithNumericId = Omit<User, "id"> & { id: number };
const row: UserWithNumericId = { id: 42, email: "ada@example.com" };Common Gotchas
All four are shallow
nested objects keep their original optionality. Write a recursive mapped type if you need deep `Partial`.
`Pick` and `Omit` keys must be assignable to `keyof T`
a typo in the key union is a type error, which is the point. Do not widen the key to `string` to silence it.
`Required` does not remove `| undefined` from the value type
`{ name?: string | undefined }` becomes `{ name: string | undefined }`, and `undefined` is still allowed as a value.
`Omit` plus an index signature still allows extra keys
the index signature is not a listed key and is not dropped. Prefer an explicit shape for public DTOs.