/** * Flatten a complex type such as a union or intersection of objects into a * single object. */ type FlatternAlias = Is extends true ? T : { [P in keyof T]: T[P]; } & {}; /** * Get the value of the given key in the given object. */ type ValueOfKey, K extends PropertyKey> = K extends keyof T ? T[K] : never; /** * Safely test whether or not the first given types extends the second. * * Needed in particular for testing if a type is "never". */ type Is = [T1] extends [T2] ? true : false; /** * Safely test whether or not the given type is "never". */ type IsNever = Is; /** * Returns whether or not the given type a record. */ type IsRecord = And>, T extends Readonly> ? true : false>; /** * Returns whether or not all the given types are records. */ type EveryIsRecord> = Ts extends readonly [infer Head, ...infer Rest] ? IsRecord extends true ? Rest extends ReadonlyArray ? EveryIsRecord : true : false : true; /** * Returns whether or not the given type is an array. */ type IsArray = And>, T extends ReadonlyArray ? true : false>; /** * Returns whether or not all the given types are arrays. */ type EveryIsArray> = Ts extends readonly [infer T1] ? IsArray : Ts extends readonly [infer Head, ...infer Rest] ? IsArray extends true ? Rest extends readonly [unknown, ...ReadonlyArray] ? EveryIsArray : false : false : false; /** * Returns whether or not the given type is an set. * * Note: This may also return true for Maps. */ type IsSet = And>, T extends Readonly> ? true : false>; /** * Returns whether or not all the given types are sets. * * Note: This may also return true if all are maps. */ type EveryIsSet> = Ts extends Readonly ? IsSet : Ts extends readonly [infer Head, ...infer Rest] ? IsSet extends true ? Rest extends readonly [unknown, ...ReadonlyArray] ? EveryIsSet : false : false : false; /** * Returns whether or not the given type is an map. */ type IsMap = And>, T extends Readonly> ? true : false>; /** * Returns whether or not all the given types are maps. */ type EveryIsMap> = Ts extends Readonly ? IsMap : Ts extends readonly [infer Head, ...infer Rest] ? IsMap extends true ? Rest extends readonly [unknown, ...ReadonlyArray] ? EveryIsMap : false : false : false; /** * And operator for types. */ type And = T1 extends false ? false : T2; /** * Not operator for types. */ type Not = T extends true ? false : true; /** * Union of the sets' values' types */ type UnionSetValues> = UnionSetValuesHelper; /** * Tail-recursive helper type for UnionSetValues. */ type UnionSetValuesHelper, Acc> = Ts extends readonly [infer Head, ...infer Rest] ? Head extends Readonly> ? Rest extends ReadonlyArray ? UnionSetValuesHelper : Acc | V1 : never : Acc; /** * Union of the maps' values' types */ type UnionMapKeys> = UnionMapKeysHelper; /** * Tail-recursive helper type for UnionMapKeys. */ type UnionMapKeysHelper, Acc> = Ts extends readonly [infer Head, ...infer Rest] ? Head extends Readonly> ? Rest extends readonly [] ? Acc | K1 : UnionMapKeysHelper : never : Acc; /** * Union of the maps' keys' types */ type UnionMapValues> = UnionMapValuesHelper; /** * Tail-recursive helper type for UnionMapValues. */ type UnionMapValuesHelper, Acc> = Ts extends readonly [infer Head, ...infer Rest] ? Head extends Readonly> ? Rest extends readonly [] ? Acc | V1 : UnionMapValuesHelper : never : Acc; /** * Get the keys of the type what match a certain criteria. */ type KeysOfType = { [K in keyof T]: T[K] extends U ? K : never; }[keyof T]; /** * Get the required keys of the type. */ type RequiredKeys = Exclude>, undefined>; /** * Get all the required keys on the types in the tuple. */ type RequiredKeysOf]> = RequiredKeysOfHelper; /** * Tail-recursive helper type for RequiredKeysOf. */ type RequiredKeysOfHelper], Acc> = Ts extends readonly [infer Head, ...infer Rest] ? Head extends Record ? Rest extends readonly [unknown, ...ReadonlyArray] ? RequiredKeysOfHelper> : Acc | RequiredKeys : never : Acc; /** * Get the optional keys of the type. */ type OptionalKeys = Exclude>; /** * Get all the optional keys on the types in the tuple. */ type OptionalKeysOf]> = OptionalKeysOfHelper; /** * Tail-recursive helper type for OptionalKeysOf. */ type OptionalKeysOfHelper], Acc> = Ts extends readonly [infer Head, ...infer Rest] ? Head extends Record ? Rest extends readonly [unknown, ...ReadonlyArray] ? OptionalKeysOfHelper> : Acc | OptionalKeys : never : Acc; /** * Filter out nevers from a tuple. */ type FilterOutNever> = FilterOutNeverHelper; /** * Tail-recursive helper type for FilterOutNever. */ type FilterOutNeverHelper, Acc extends ReadonlyArray> = T extends readonly [] ? Acc : T extends readonly [infer Head, ...infer Rest] ? IsNever extends true ? FilterOutNeverHelper : FilterOutNeverHelper : T; /** * Is the type a tuple? */ type IsTuple> = T extends readonly [] ? true : T extends readonly [unknown, ...ReadonlyArray] ? true : false; /** * Mapping of merge function URIs to the merge function type. */ interface DeepMergeMergeFunctionURItoKind, MF extends DeepMergeMergeFunctionsURIs, in out M> { readonly DeepMergeLeafURI: DeepMergeLeaf; readonly DeepMergeRecordsDefaultURI: DeepMergeRecordsDefaultHKT; readonly DeepMergeArraysDefaultURI: DeepMergeArraysDefaultHKT; readonly DeepMergeSetsDefaultURI: DeepMergeSetsDefaultHKT; readonly DeepMergeMapsDefaultURI: DeepMergeMapsDefaultHKT; } /** * Get the type of the given merge function via its URI. */ type DeepMergeMergeFunctionKind, MF extends DeepMergeMergeFunctionsURIs, M> = DeepMergeMergeFunctionURItoKind[URI]; /** * A union of all valid merge function URIs. */ type DeepMergeMergeFunctionURIs = keyof DeepMergeMergeFunctionURItoKind, DeepMergeMergeFunctionsURIs, unknown>; /** * The merge functions to use when deep merging. */ type DeepMergeMergeFunctionsURIs = Readonly<{ /** * The merge function to merge records with. */ DeepMergeRecordsURI: DeepMergeMergeFunctionURIs; /** * The merge function to merge arrays with. */ DeepMergeArraysURI: DeepMergeMergeFunctionURIs; /** * The merge function to merge sets with. */ DeepMergeSetsURI: DeepMergeMergeFunctionURIs; /** * The merge function to merge maps with. */ DeepMergeMapsURI: DeepMergeMergeFunctionURIs; /** * The merge function to merge other things with. */ DeepMergeOthersURI: DeepMergeMergeFunctionURIs; }>; /** * Deep merge types. */ type DeepMergeHKT, MF extends DeepMergeMergeFunctionsURIs, M> = IsTuple extends true ? Ts extends readonly [] ? undefined : Ts extends readonly [infer T1] ? T1 : EveryIsArray extends true ? DeepMergeArraysHKT : EveryIsMap extends true ? DeepMergeMapsHKT : EveryIsSet extends true ? DeepMergeSetsHKT : EveryIsRecord extends true ? DeepMergeRecordsHKT : DeepMergeOthersHKT : unknown; /** * Deep merge records. */ type DeepMergeRecordsHKT, MF extends DeepMergeMergeFunctionsURIs, M> = DeepMergeMergeFunctionKind; /** * Deep merge arrays. */ type DeepMergeArraysHKT, MF extends DeepMergeMergeFunctionsURIs, M> = DeepMergeMergeFunctionKind; /** * Deep merge sets. */ type DeepMergeSetsHKT, MF extends DeepMergeMergeFunctionsURIs, M> = DeepMergeMergeFunctionKind; /** * Deep merge maps. */ type DeepMergeMapsHKT, MF extends DeepMergeMergeFunctionsURIs, M> = DeepMergeMergeFunctionKind; /** * Deep merge other things. */ type DeepMergeOthersHKT, MF extends DeepMergeMergeFunctionsURIs, M> = DeepMergeMergeFunctionKind; /** * The merge function that returns a leaf. */ type DeepMergeLeafURI = "DeepMergeLeafURI"; /** * Get the leaf type from many types that can't be merged. * * @deprecated Use `DeepMergeLeaf` instead. */ type DeepMergeLeafHKT> = DeepMergeLeaf; /** * Get the leaf type from many types that can't be merged. */ type DeepMergeLeaf> = Ts extends readonly [] ? never : Ts extends readonly [infer T] ? T : Ts extends readonly [...infer Rest, infer Tail] ? IsNever extends true ? Rest extends ReadonlyArray ? DeepMergeLeaf : never : Tail : never; /** * The meta data deepmerge is able to provide. */ type DeepMergeBuiltInMetaData = Readonly<{ key: PropertyKey; parents: ReadonlyArray>>; }>; /** * The default merge function to merge records with. */ type DeepMergeRecordsDefaultURI = "DeepMergeRecordsDefaultURI"; /** * The default merge function to merge arrays with. */ type DeepMergeArraysDefaultURI = "DeepMergeArraysDefaultURI"; /** * The default merge function to merge sets with. */ type DeepMergeSetsDefaultURI = "DeepMergeSetsDefaultURI"; /** * The default merge function to merge maps with. */ type DeepMergeMapsDefaultURI = "DeepMergeMapsDefaultURI"; /** * The default merge functions to use when deep merging. */ type DeepMergeMergeFunctionsDefaultURIs = Readonly<{ DeepMergeRecordsURI: DeepMergeRecordsDefaultURI; DeepMergeArraysURI: DeepMergeArraysDefaultURI; DeepMergeSetsURI: DeepMergeSetsDefaultURI; DeepMergeMapsURI: DeepMergeMapsDefaultURI; DeepMergeOthersURI: DeepMergeLeafURI; }>; /** * A union of all the props that should not be included in type information for * merged records. */ type BlacklistedRecordProps = "__proto__"; /** * Deep merge records. */ type DeepMergeRecordsDefaultHKT, MF extends DeepMergeMergeFunctionsURIs, M> = Ts extends Readonly>]> ? FlatternAlias, BlacklistedRecordProps>> : {}; /** * Deep merge record props. */ type DeepMergeRecordsDefaultHKTInternalProps], MF extends DeepMergeMergeFunctionsURIs, M> = { [K in OptionalKeysOf]?: DeepMergeHKT, MF, M>; } & { [K in RequiredKeysOf]: DeepMergeHKT, MF, M>; }; /** * Get the value of the property. */ type DeepMergeRecordsDefaultHKTInternalPropValue], K extends PropertyKey, M> = FilterOutNever>; /** * Tail-recursive helper type for DeepMergeRecordsDefaultHKTInternalPropValue. */ type DeepMergeRecordsDefaultHKTInternalPropValueHelper], K extends PropertyKey, M, Acc extends ReadonlyArray> = Ts extends readonly [ infer Head extends Readonly>, ...infer Rest ] ? Rest extends readonly [unknown, ...ReadonlyArray] ? DeepMergeRecordsDefaultHKTInternalPropValueHelper ]> : [...Acc, ValueOfKey] : never; /** * Deep merge 2 arrays. */ type DeepMergeArraysDefaultHKT, MF extends DeepMergeMergeFunctionsURIs, M> = DeepMergeArraysDefaultHKTHelper; /** * Tail-recursive helper type for DeepMergeArraysDefaultHKT. */ type DeepMergeArraysDefaultHKTHelper, MF extends DeepMergeMergeFunctionsURIs, M, Acc extends ReadonlyArray> = Ts extends readonly [ infer Head extends ReadonlyArray, ...infer Rest ] ? Rest extends readonly [ ReadonlyArray, ...ReadonlyArray> ] ? DeepMergeArraysDefaultHKTHelper : [...Acc, ...Head] : never; /** * Deep merge 2 sets. */ type DeepMergeSetsDefaultHKT> = Set>; /** * Deep merge 2 maps. */ type DeepMergeMapsDefaultHKT> = Map, UnionMapValues>; /** * Get the merge functions with defaults apply from the given subset. */ type GetDeepMergeMergeFunctionsURIs> = Readonly<{ DeepMergeRecordsURI: PMF["DeepMergeRecordsURI"] extends keyof DeepMergeMergeFunctionURItoKind ? PMF["DeepMergeRecordsURI"] : DeepMergeRecordsDefaultURI; DeepMergeArraysURI: PMF["DeepMergeArraysURI"] extends keyof DeepMergeMergeFunctionURItoKind ? PMF["DeepMergeArraysURI"] : DeepMergeArraysDefaultURI; DeepMergeSetsURI: PMF["DeepMergeSetsURI"] extends keyof DeepMergeMergeFunctionURItoKind ? PMF["DeepMergeSetsURI"] : DeepMergeSetsDefaultURI; DeepMergeMapsURI: PMF["DeepMergeMapsURI"] extends keyof DeepMergeMergeFunctionURItoKind ? PMF["DeepMergeMapsURI"] : DeepMergeMapsDefaultURI; DeepMergeOthersURI: PMF["DeepMergeOthersURI"] extends keyof DeepMergeMergeFunctionURItoKind ? PMF["DeepMergeOthersURI"] : DeepMergeLeafURI; }>; /** * The default merge functions. */ type MergeFunctions$1 = { mergeRecords: typeof mergeRecords$1; mergeArrays: typeof mergeArrays$1; mergeSets: typeof mergeSets$1; mergeMaps: typeof mergeMaps$1; mergeOthers: typeof mergeOthers$1; }; /** * The default strategy to merge records into a target record. * * @param m_target - The result will be mutated into this record * @param values - The records (including the target's value if there is one). */ declare function mergeRecords$1>, U extends DeepMergeMergeIntoFunctionUtils, M, MM extends DeepMergeBuiltInMetaData>(m_target: Reference>, values: Ts, utils: U, meta: M | undefined): void; /** * The default strategy to merge arrays into a target array. * * @param m_target - The result will be mutated into this array * @param values - The arrays (including the target's value if there is one). */ declare function mergeArrays$1>>(m_target: Reference, values: Ts): void; /** * The default strategy to merge sets into a target set. * * @param m_target - The result will be mutated into this set * @param values - The sets (including the target's value if there is one). */ declare function mergeSets$1>>>(m_target: Reference>, values: Ts): void; /** * The default strategy to merge maps into a target map. * * @param m_target - The result will be mutated into this map * @param values - The maps (including the target's value if there is one). */ declare function mergeMaps$1>>>(m_target: Reference>, values: Ts): void; /** * Set the target to the last value. */ declare function mergeOthers$1>(m_target: Reference, values: Ts): void; /** * The default merge functions. */ type MergeFunctions = { mergeRecords: typeof mergeRecords; mergeArrays: typeof mergeArrays; mergeSets: typeof mergeSets; mergeMaps: typeof mergeMaps; mergeOthers: typeof mergeOthers; }; /** * The default strategy to merge records. * * @param values - The records. */ declare function mergeRecords>, U extends DeepMergeMergeFunctionUtils, MF extends DeepMergeMergeFunctionsURIs, M, MM extends DeepMergeBuiltInMetaData>(values: Ts, utils: U, meta: M | undefined): DeepMergeRecordsDefaultHKT; /** * The default strategy to merge arrays. * * @param values - The arrays. */ declare function mergeArrays>, MF extends DeepMergeMergeFunctionsURIs, M>(values: Ts): DeepMergeArraysDefaultHKT; /** * The default strategy to merge sets. * * @param values - The sets. */ declare function mergeSets>>>(values: Ts): DeepMergeSetsDefaultHKT; /** * The default strategy to merge maps. * * @param values - The maps. */ declare function mergeMaps>>>(values: Ts): DeepMergeMapsDefaultHKT; /** * Get the last value in the given array. */ declare function mergeOthers>(values: Ts): unknown; /** * The options the user can pass to customize deepmerge. */ type DeepMergeOptions> = DeepMergeBuiltInMetaData> = Partial>; /** * The options the user can pass to customize deepmergeInto. */ type DeepMergeIntoOptions> = DeepMergeBuiltInMetaData> = Partial>; type MetaDataUpdater = (previousMeta: M | undefined, metaMeta: Readonly>) => M; /** * All the options the user can pass to customize deepmerge. */ type DeepMergeOptionsFull = Readonly<{ mergeRecords: DeepMergeMergeFunctions["mergeRecords"] | false; mergeArrays: DeepMergeMergeFunctions["mergeArrays"] | false; mergeMaps: DeepMergeMergeFunctions["mergeMaps"] | false; mergeSets: DeepMergeMergeFunctions["mergeSets"] | false; mergeOthers: DeepMergeMergeFunctions["mergeOthers"]; metaDataUpdater: MetaDataUpdater; enableImplicitDefaultMerging: boolean; }>; /** * All the options the user can pass to customize deepmergeInto. */ type DeepMergeIntoOptionsFull = Readonly<{ mergeRecords: DeepMergeMergeIntoFunctions["mergeRecords"] | false; mergeArrays: DeepMergeMergeIntoFunctions["mergeArrays"] | false; mergeMaps: DeepMergeMergeIntoFunctions["mergeMaps"] | false; mergeSets: DeepMergeMergeIntoFunctions["mergeSets"] | false; mergeOthers: DeepMergeMergeIntoFunctions["mergeOthers"]; metaDataUpdater: MetaDataUpdater; }>; /** * An object that has a reference to a value. */ type Reference = { value: T; }; /** * All the merge functions that deepmerge uses. */ type DeepMergeMergeFunctions = Readonly<{ mergeRecords: >>, U extends DeepMergeMergeFunctionUtils>(values: Ts, utils: U, meta: M | undefined) => unknown; mergeArrays: >, U extends DeepMergeMergeFunctionUtils>(values: Ts, utils: U, meta: M | undefined) => unknown; mergeMaps: >>, U extends DeepMergeMergeFunctionUtils>(values: Ts, utils: U, meta: M | undefined) => unknown; mergeSets: >>, U extends DeepMergeMergeFunctionUtils>(values: Ts, utils: U, meta: M | undefined) => unknown; mergeOthers: , U extends DeepMergeMergeFunctionUtils>(values: Ts, utils: U, meta: M | undefined) => unknown; }>; type DeepMergeMergeIntoFunctionsReturnType = void | symbol; /** * All the merge functions that deepmerge uses. */ type DeepMergeMergeIntoFunctions = Readonly<{ mergeRecords: >>, U extends DeepMergeMergeIntoFunctionUtils>(m_target: Reference>, values: Ts, utils: U, meta: M | undefined) => DeepMergeMergeIntoFunctionsReturnType; mergeArrays: >, U extends DeepMergeMergeIntoFunctionUtils>(m_target: Reference, values: Ts, utils: U, meta: M | undefined) => DeepMergeMergeIntoFunctionsReturnType; mergeMaps: >>, U extends DeepMergeMergeIntoFunctionUtils>(m_target: Reference>, values: Ts, utils: U, meta: M | undefined) => DeepMergeMergeIntoFunctionsReturnType; mergeSets: >>, U extends DeepMergeMergeIntoFunctionUtils>(m_target: Reference>, values: Ts, utils: U, meta: M | undefined) => DeepMergeMergeIntoFunctionsReturnType; mergeOthers: , U extends DeepMergeMergeIntoFunctionUtils>(m_target: Reference, values: Ts, utils: U, meta: M | undefined) => DeepMergeMergeIntoFunctionsReturnType; }>; /** * The utils provided to the merge functions. */ type DeepMergeMergeFunctionUtils = Readonly<{ mergeFunctions: DeepMergeMergeFunctions; defaultMergeFunctions: MergeFunctions; metaDataUpdater: MetaDataUpdater; deepmerge: >(...values: Ts) => unknown; useImplicitDefaultMerging: boolean; actions: Readonly<{ defaultMerge: symbol; skip: symbol; }>; }>; /** * The utils provided to the merge functions. */ type DeepMergeMergeIntoFunctionUtils = Readonly<{ mergeFunctions: DeepMergeMergeIntoFunctions; defaultMergeFunctions: MergeFunctions$1; metaDataUpdater: MetaDataUpdater; deepmergeInto: >(target: Target, ...values: Ts) => void; actions: Readonly<{ defaultMerge: symbol; }>; }>; /** * Deeply merge objects. * * @param objects - The objects to merge. */ declare function deepmerge>>(...objects: readonly [...Ts]): DeepMergeHKT; /** * Deeply merge two or more objects using the given options. * * @param options - The options on how to customize the merge function. */ declare function deepmergeCustom>(options: DeepMergeOptions): >(...objects: Ts) => DeepMergeHKT, DeepMergeBuiltInMetaData>; /** * Deeply merge two or more objects using the given options and meta data. * * @param options - The options on how to customize the merge function. * @param rootMetaData - The meta data passed to the root items' being merged. */ declare function deepmergeCustom, MetaData, MetaMetaData extends DeepMergeBuiltInMetaData = DeepMergeBuiltInMetaData>(options: DeepMergeOptions, rootMetaData?: MetaData): >(...objects: Ts) => DeepMergeHKT, MetaData>; /** * Deeply merge objects into a target. * * @param target - This object will be mutated with the merge result. * @param objects - The objects to merge into the target. */ declare function deepmergeInto(target: T, ...objects: ReadonlyArray): void; /** * Deeply merge objects into a target. * * @param target - This object will be mutated with the merge result. * @param objects - The objects to merge into the target. */ declare function deepmergeInto>(target: Target, ...objects: Ts): asserts target is FlatternAlias>; /** * Deeply merge two or more objects using the given options. * * @param options - The options on how to customize the merge function. */ declare function deepmergeIntoCustom(options: DeepMergeIntoOptions): >(target: Target, ...objects: Ts) => void; /** * Deeply merge two or more objects using the given options and meta data. * * @param options - The options on how to customize the merge function. * @param rootMetaData - The meta data passed to the root items' being merged. */ declare function deepmergeIntoCustom(options: DeepMergeIntoOptions, rootMetaData?: MetaData): >(target: Target, ...objects: Ts) => void; export { DeepMergeArraysDefaultHKT, DeepMergeBuiltInMetaData, DeepMergeHKT, DeepMergeIntoOptions, DeepMergeLeaf, DeepMergeLeafHKT, DeepMergeLeafURI, DeepMergeMapsDefaultHKT, DeepMergeMergeFunctionURItoKind, DeepMergeMergeFunctionUtils, DeepMergeMergeFunctionsDefaultURIs, MergeFunctions as DeepMergeMergeFunctionsDefaults, DeepMergeMergeFunctionsURIs, DeepMergeMergeIntoFunctionUtils, MergeFunctions$1 as DeepMergeMergeIntoFunctionsDefaults, DeepMergeOptions, DeepMergeRecordsDefaultHKT, DeepMergeSetsDefaultHKT, Reference as DeepMergeValueReference, deepmerge, deepmergeCustom, deepmergeInto, deepmergeIntoCustom };