export type DeepPartial<T> = T extends Function ? T : (T extends object ? { [P in keyof T]?: DeepPartial<T[P]>; } : T);
Before [email protected]
type DeepPartial<T> = {
[P in keyof T]?: T[P] extends Array<infer U>
? Array<DeepPartial<U>>
: T[P] extends ReadonlyArray<infer U>
? ReadonlyArray<DeepPartial<U>>
: DeepPartial<T[P]>
};
Array elements are made optional too, which is quite disputable.
Example:
I'd expect this result from
DeepPartial<Shape>
:However it currently resolves this way:
It is disputable since
Partial<string[]>
resolves to(string | undefined)[]
, but this is intuitive when I applyPartial
directly on an array. But if I applyDeepPartial
to express some large partial structure, I would not expectundefined
in array elements.It can be fixed this way: