stack

Home > @infiniteobjects/type-utils > PartialDeep

PartialDeep type

Create a type from another type with all keys and nested keys set to optional.

Use-cases: - Merging a default settings/config object with another object, the second object would be a deep partial of the default object. - Mocking and testing complex entities, where populating an entire object with its keys would be redundant in terms of the mock or test.

Signature:

export type PartialDeep<T> = T extends Primitive ? Partial<T> : T extends Map<infer KeyType, infer ValueType> ? PartialMapDeep<KeyType, ValueType> : T extends Set<infer ItemType> ? PartialSetDeep<ItemType> : T extends ReadonlyMap<infer KeyType, infer ValueType> ? PartialReadonlyMapDeep<KeyType, ValueType> : T extends ReadonlySet<infer ItemType> ? PartialReadonlySetDeep<ItemType> : T extends (...args: any[]) => unknown ? T | undefined : T extends object ? T extends Array<infer ItemType> ? ItemType[] extends T ? Array<PartialDeep<ItemType | undefined>> : PartialObjectDeep<T> : PartialObjectDeep<T> : unknown;

References: Primitive, PartialDeep