Skip to main content
← Gists
typescript Feb 19, 2026

DeepPartial for Patch Objects

Make every nested field optional for update payloads.

Use DeepPartial for patch payloads where any nested field may be omitted.

Type

deep-partial.ts
type DeepPartial<T> = T extends Function
? T
: T extends object
  ? { [K in keyof T]?: DeepPartial<T[K]> }
  : T

type User = {
id: string
profile: {
  name: string
  socials: {
    github: string
  }
}
}

type UserPatch = DeepPartial<User>