1 import {Primitive} from './basic';
4 Create a type from another type with all keys and nested keys set to optional.
7 - Merging a default settings/config object with another object, the second object would be a deep partial of the default object.
8 - Mocking and testing complex entities, where populating an entire object with its keys would be redundant in terms of the mock or test.
12 import {PartialDeep} from 'type-fest';
14 const settings: Settings = {
24 const applySavedSettings = (savedSettings: PartialDeep<Settings>) => {
25 return {...settings, ...savedSettings};
28 settings = applySavedSettings({textEditor: {fontWeight: 500}});
31 export type PartialDeep<T> = T extends Primitive
33 : T extends Map<infer KeyType, infer ValueType>
34 ? PartialMapDeep<KeyType, ValueType>
35 : T extends Set<infer ItemType>
36 ? PartialSetDeep<ItemType>
37 : T extends ReadonlyMap<infer KeyType, infer ValueType>
38 ? PartialReadonlyMapDeep<KeyType, ValueType>
39 : T extends ReadonlySet<infer ItemType>
40 ? PartialReadonlySetDeep<ItemType>
41 : T extends ((...arguments: any[]) => unknown)
44 ? PartialObjectDeep<T>
48 Same as `PartialDeep`, but accepts only `Map`s and as inputs. Internal helper for `PartialDeep`.
50 interface PartialMapDeep<KeyType, ValueType> extends Map<PartialDeep<KeyType>, PartialDeep<ValueType>> {}
53 Same as `PartialDeep`, but accepts only `Set`s as inputs. Internal helper for `PartialDeep`.
55 interface PartialSetDeep<T> extends Set<PartialDeep<T>> {}
58 Same as `PartialDeep`, but accepts only `ReadonlyMap`s as inputs. Internal helper for `PartialDeep`.
60 interface PartialReadonlyMapDeep<KeyType, ValueType> extends ReadonlyMap<PartialDeep<KeyType>, PartialDeep<ValueType>> {}
63 Same as `PartialDeep`, but accepts only `ReadonlySet`s as inputs. Internal helper for `PartialDeep`.
65 interface PartialReadonlySetDeep<T> extends ReadonlySet<PartialDeep<T>> {}
68 Same as `PartialDeep`, but accepts only `object`s as inputs. Internal helper for `PartialDeep`.
70 type PartialObjectDeep<ObjectType extends object> = {
71 [KeyType in keyof ObjectType]?: PartialDeep<ObjectType[KeyType]>