0Pricing
TypeScript Academy · Lesson

DeepPartial and DeepReadonly

Build recursive versions of Partial and Readonly.

Why Deep Utility Types?

Built-in Partial and Readonly only apply one level deep. For nested objects, you need recursive versions.

interface Config {
  db: { host: string; port: number };
  app: { name: string };
}
type Shallow = Partial<Config>;
// Shallow.db is still required — only top level is optional

Implementing DeepPartial

Recursively map over object properties, making each one optional and recursively applying DeepPartial if the property value is an object.

type DeepPartial<T> = T extends object
  ? { [K in keyof T]?: DeepPartial<T[K]> }
  : T;

All lessons in this course

  1. DeepPartial and DeepReadonly
  2. Flatten and UnwrapPromise Utilities
  3. TupleToUnion and UnionToIntersection
  4. Publishing a Type Utility Library
← Back to TypeScript Academy