From ca94270da73d0a071043ef0e8936b17c444e40ab Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Thu, 6 Jun 2024 13:14:07 +1200 Subject: [PATCH] fix: merge functions' types issue was caused by bug in the bundling process --- src/deepmerge-into.ts | 2 +- src/deepmerge.ts | 2 +- src/defaults/into.ts | 31 +++++++++++++++++++++---------- src/defaults/vanilla.ts | 25 ++++++++++++++++++------- 4 files changed, 41 insertions(+), 19 deletions(-) diff --git a/src/deepmerge-into.ts b/src/deepmerge-into.ts index 1ad0ca88..887ce8bb 100644 --- a/src/deepmerge-into.ts +++ b/src/deepmerge-into.ts @@ -3,7 +3,7 @@ import { defaultFilterValues, defaultMetaDataUpdater, } from "./defaults/general"; -import * as defaultMergeIntoFunctions from "./defaults/into"; +import { mergeIntoFunctions as defaultMergeIntoFunctions } from "./defaults/into"; import { type DeepMergeBuiltInMetaData, type DeepMergeFunctionsDefaultURIs, diff --git a/src/deepmerge.ts b/src/deepmerge.ts index 94d37f14..6144f8f7 100644 --- a/src/deepmerge.ts +++ b/src/deepmerge.ts @@ -3,7 +3,7 @@ import { defaultFilterValues, defaultMetaDataUpdater, } from "./defaults/general"; -import * as defaultMergeFunctions from "./defaults/vanilla"; +import { mergeFunctions as defaultMergeFunctions } from "./defaults/vanilla"; import { type DeepMergeBuiltInMetaData, type DeepMergeFunctionsDefaultURIs, diff --git a/src/defaults/into.ts b/src/defaults/into.ts index b0d1baa4..857f0699 100644 --- a/src/defaults/into.ts +++ b/src/defaults/into.ts @@ -10,11 +10,11 @@ import { getIterableOfIterables, getKeys, objectHasProperty } from "../utils"; * The default merge functions. */ export type MergeFunctions = { - mergeRecords: typeof mergeRecords; - mergeArrays: typeof mergeArrays; - mergeSets: typeof mergeSets; - mergeMaps: typeof mergeMaps; - mergeOthers: typeof mergeOthers; + mergeRecords: typeof mergeRecordsInto; + mergeArrays: typeof mergeArraysInto; + mergeSets: typeof mergeSetsInto; + mergeMaps: typeof mergeMapsInto; + mergeOthers: typeof mergeOthersInto; }; /** @@ -23,7 +23,7 @@ export type MergeFunctions = { * @param m_target - The result will be mutated into this record * @param values - The records (including the target's value if there is one). */ -export function mergeRecords< +function mergeRecordsInto< Ts extends ReadonlyArray>, U extends DeepMergeIntoFunctionUtils, M, @@ -79,7 +79,7 @@ export function mergeRecords< * @param m_target - The result will be mutated into this array * @param values - The arrays (including the target's value if there is one). */ -export function mergeArrays>>( +function mergeArraysInto>>( m_target: Reference, values: Ts, ): void { @@ -92,7 +92,7 @@ export function mergeArrays>>( * @param m_target - The result will be mutated into this set * @param values - The sets (including the target's value if there is one). */ -export function mergeSets< +function mergeSetsInto< Ts extends ReadonlyArray>>, >(m_target: Reference>, values: Ts): void { for (const value of getIterableOfIterables(values.slice(1))) { @@ -106,7 +106,7 @@ export function mergeSets< * @param m_target - The result will be mutated into this map * @param values - The maps (including the target's value if there is one). */ -export function mergeMaps< +function mergeMapsInto< Ts extends ReadonlyArray>>, >(m_target: Reference>, values: Ts): void { for (const [key, value] of getIterableOfIterables(values.slice(1))) { @@ -117,9 +117,20 @@ export function mergeMaps< /** * Set the target to the last non-undefined value. */ -export function mergeOthers>( +function mergeOthersInto>( m_target: Reference, values: Ts, ) { m_target.value = values.at(-1); } + +/** + * The merge functions. + */ +export const mergeIntoFunctions = { + mergeRecords: mergeRecordsInto, + mergeArrays: mergeArraysInto, + mergeSets: mergeSetsInto, + mergeMaps: mergeMapsInto, + mergeOthers: mergeOthersInto, +}; diff --git a/src/defaults/vanilla.ts b/src/defaults/vanilla.ts index e28be1f6..b5967c2a 100644 --- a/src/defaults/vanilla.ts +++ b/src/defaults/vanilla.ts @@ -27,7 +27,7 @@ export type MergeFunctions = { * * @param values - The records. */ -export function mergeRecords< +function mergeRecords< Ts extends ReadonlyArray>, U extends DeepMergeUtils, Fs extends DeepMergeFunctionsURIs, @@ -88,7 +88,7 @@ export function mergeRecords< * * @param values - The arrays. */ -export function mergeArrays< +function mergeArrays< Ts extends ReadonlyArray>, Fs extends DeepMergeFunctionsURIs, M, @@ -101,9 +101,9 @@ export function mergeArrays< * * @param values - The sets. */ -export function mergeSets< - Ts extends ReadonlyArray>>, ->(values: Ts): DeepMergeSetsDefaultHKT { +function mergeSets>>>( + values: Ts, +): DeepMergeSetsDefaultHKT { return new Set(getIterableOfIterables(values)) as DeepMergeSetsDefaultHKT; } @@ -112,7 +112,7 @@ export function mergeSets< * * @param values - The maps. */ -export function mergeMaps< +function mergeMaps< Ts extends ReadonlyArray>>, >(values: Ts): DeepMergeMapsDefaultHKT { return new Map(getIterableOfIterables(values)) as DeepMergeMapsDefaultHKT; @@ -121,6 +121,17 @@ export function mergeMaps< /** * Get the last non-undefined value in the given array. */ -export function mergeOthers>(values: Ts) { +function mergeOthers>(values: Ts) { return values.at(-1); } + +/** + * The merge functions. + */ +export const mergeFunctions = { + mergeRecords, + mergeArrays, + mergeSets, + mergeMaps, + mergeOthers, +};