Skip to content

Commit

Permalink
fix: merge functions' types
Browse files Browse the repository at this point in the history
issue was caused by bug in the bundling process
  • Loading branch information
RebeccaStevens committed Jun 6, 2024
1 parent 068d886 commit ca94270
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/deepmerge-into.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/deepmerge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
31 changes: 21 additions & 10 deletions src/defaults/into.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

/**
Expand All @@ -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<Record<PropertyKey, unknown>>,
U extends DeepMergeIntoFunctionUtils<M, MM>,
M,
Expand Down Expand Up @@ -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<Ts extends ReadonlyArray<ReadonlyArray<unknown>>>(
function mergeArraysInto<Ts extends ReadonlyArray<ReadonlyArray<unknown>>>(
m_target: Reference<unknown[]>,
values: Ts,
): void {
Expand All @@ -92,7 +92,7 @@ export function mergeArrays<Ts extends ReadonlyArray<ReadonlyArray<unknown>>>(
* @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<Readonly<ReadonlySet<unknown>>>,
>(m_target: Reference<Set<unknown>>, values: Ts): void {
for (const value of getIterableOfIterables(values.slice(1))) {
Expand All @@ -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<Readonly<ReadonlyMap<unknown, unknown>>>,
>(m_target: Reference<Map<unknown, unknown>>, values: Ts): void {
for (const [key, value] of getIterableOfIterables(values.slice(1))) {
Expand All @@ -117,9 +117,20 @@ export function mergeMaps<
/**
* Set the target to the last non-undefined value.
*/
export function mergeOthers<Ts extends ReadonlyArray<unknown>>(
function mergeOthersInto<Ts extends ReadonlyArray<unknown>>(
m_target: Reference<unknown>,
values: Ts,
) {
m_target.value = values.at(-1);
}

/**
* The merge functions.
*/
export const mergeIntoFunctions = {
mergeRecords: mergeRecordsInto,
mergeArrays: mergeArraysInto,
mergeSets: mergeSetsInto,
mergeMaps: mergeMapsInto,
mergeOthers: mergeOthersInto,
};
25 changes: 18 additions & 7 deletions src/defaults/vanilla.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export type MergeFunctions = {
*
* @param values - The records.
*/
export function mergeRecords<
function mergeRecords<
Ts extends ReadonlyArray<Record<PropertyKey, unknown>>,
U extends DeepMergeUtils<M, MM>,
Fs extends DeepMergeFunctionsURIs,
Expand Down Expand Up @@ -88,7 +88,7 @@ export function mergeRecords<
*
* @param values - The arrays.
*/
export function mergeArrays<
function mergeArrays<
Ts extends ReadonlyArray<ReadonlyArray<unknown>>,
Fs extends DeepMergeFunctionsURIs,
M,
Expand All @@ -101,9 +101,9 @@ export function mergeArrays<
*
* @param values - The sets.
*/
export function mergeSets<
Ts extends ReadonlyArray<Readonly<ReadonlySet<unknown>>>,
>(values: Ts): DeepMergeSetsDefaultHKT<Ts> {
function mergeSets<Ts extends ReadonlyArray<Readonly<ReadonlySet<unknown>>>>(
values: Ts,
): DeepMergeSetsDefaultHKT<Ts> {
return new Set(getIterableOfIterables(values)) as DeepMergeSetsDefaultHKT<Ts>;
}

Expand All @@ -112,7 +112,7 @@ export function mergeSets<
*
* @param values - The maps.
*/
export function mergeMaps<
function mergeMaps<
Ts extends ReadonlyArray<Readonly<ReadonlyMap<unknown, unknown>>>,
>(values: Ts): DeepMergeMapsDefaultHKT<Ts> {
return new Map(getIterableOfIterables(values)) as DeepMergeMapsDefaultHKT<Ts>;
Expand All @@ -121,6 +121,17 @@ export function mergeMaps<
/**
* Get the last non-undefined value in the given array.
*/
export function mergeOthers<Ts extends ReadonlyArray<unknown>>(values: Ts) {
function mergeOthers<Ts extends ReadonlyArray<unknown>>(values: Ts) {
return values.at(-1);
}

/**
* The merge functions.
*/
export const mergeFunctions = {
mergeRecords,
mergeArrays,
mergeSets,
mergeMaps,
mergeOthers,
};

0 comments on commit ca94270

Please sign in to comment.