type PartialDeep = T extends | string | number | bigint | boolean | null | undefined | symbol | Date ? T | undefined : // Arrays, Sets and Maps and their readonly counterparts have their items made // deeply partial, but their own instances are left untouched T extends Array ? Array> : T extends ReadonlyArray ? ReadonlyArray : T extends Set ? Set> : T extends ReadonlySet ? ReadonlySet : T extends Map ? Map, PartialDeep> : T extends ReadonlyMap ? ReadonlyMap, PartialDeep> : // ...and finally, all other objects. { [K in keyof T]?: PartialDeep; };