Skip to content

Commit

Permalink
fix: typescript cannot remember inference on indexed types
Browse files Browse the repository at this point in the history
  • Loading branch information
Lordfirespeed committed Nov 1, 2024
1 parent bbffd3d commit 678456f
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/lib/adapters/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ export const filterByPrefixKey = (
}, {});
};

export function deepMerge(target: unknown, ...sources: unknown[]) {
export function deepMerge(
target: Partial<Record<string, unknown>>,
...sources: unknown[]
): Partial<Record<string, unknown>> {
if (!sources.length) {
return target;
}
Expand All @@ -34,11 +37,13 @@ export function deepMerge(target: unknown, ...sources: unknown[]) {
return;
}

if (!target[key]) {
target[key] = {};
let subTarget = target[key]
if (!isMergeableObject(subTarget)) {
target[key] = subTarget = {}
return
}

deepMerge(target[key], source[key]);
deepMerge(subTarget, source[key]);
});
}

Expand Down

0 comments on commit 678456f

Please sign in to comment.