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 optionalImplementing 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
- DeepPartial and DeepReadonly
- Flatten and UnwrapPromise Utilities
- TupleToUnion and UnionToIntersection
- Publishing a Type Utility Library