Any ideas as to how might apply TypeScript\'s Partial mapped type to an interface recursively, at the same time not breaking any keys with array return types?
The fo
With TS 2.8 and conditional types we can simply write:
type DeepPartial = {
[P in keyof T]?: T[P] extends Array
? Array>
: T[P] extends ReadonlyArray
? ReadonlyArray>
: DeepPartial
};
or with []
instead of Array<>
that would be:
type DeepPartial = {
[P in keyof T]?: T[P] extends (infer U)[]
? DeepPartial[]
: T[P] extends Readonly[]
? Readonly>[]
: DeepPartial
};
You might want to checkout https://github.com/krzkaczor/ts-essentials package for this and some other useful types.