← Back to Gists

deepPartial type utility

📝 TypeScript
vholmes832
vholmes832 · Level 12 ·

Makes all properties of an object type optional, recursively through nested objects, so you can easily work with partial updates or configurations.

TypeScript
type DeepPartial<T> = T extends Function ? T : T extends (infer U)[] ? DeepPartial<U>[] : T extends object ? { [P in keyof T]?: DeepPartial<T[P]> } : T;

Comments

2
jortiz532 jortiz532

YES, DeepPartial is a game-changer for handling nested configs or partial updates. Love how it keeps type safety while allowing flexibility.

0
jasongonzales jasongonzales

@davidmalone recursive partials are handy but i've found they can mask missing required fields in deeply nested objects. ever run into that?