object-transforms

Partial<T>

Constructs a type where every property of T is set to optional. Useful for representing update payloads, patch objects, and configuration overrides where all fields may be omitted.

type Partial<T> = { [P in keyof T]?: T[P] }

Usage patterns

Pattern Purpose
Partial<User> Make every top-level field of User optional
Partial<Pick<T, K>> Make only a chosen subset of properties optional
Object.assign({}, defaults, partial) Common runtime companion to merge partial patches
DeepPartial<T> Custom recursive version — Partial itself is not deep

Examples

interface User { id: number; name: string; email: string }
type PatchUser = Partial<User>;

All three fields become optional: { id?; name?; email? }

function update(user: User, patch: Partial<User>): User {
  return { ...user, ...patch };
}

Classic patch-merge signature accepting any subset of User fields

type Config = { host: string; port: number; ssl: { enabled: boolean } };
const c: Partial<Config> = { ssl: {} };

Errors: nested ssl.enabled is still required because Partial is shallow

type Optional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;

Selective-optional helper built by composing Partial with Pick/Omit

Gotcha

Partial is shallow — nested object properties keep their required fields. Also weakens type safety: forgetting a field will not error, so pair with runtime validation for API inputs.

Related utility types

← All TS utility types · TypeScript vs JavaScript · any vs unknown vs never