Skip to content

Commit

Permalink
fix: use alternative DeepMergeAll approach to get around bad circular…
Browse files Browse the repository at this point in the history
… reference
  • Loading branch information
Rebecca Stevens committed Nov 9, 2020
1 parent 9185f1f commit d409acd
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@
type DeepMergeAll<
Ts extends readonly any[],
Options extends deepmerge.Options
> = Ts extends readonly [infer T1, ...any[]]
? Ts extends readonly [any, infer T2, ...infer TRest]
? TRest extends readonly never[]
? DeepMerge<T1, T2, Options>
: unknown // DeepMerge<T1, DeepMergeAll<[T2, ...TRest], Options>, Options>
: T1
: never;

> = {
0: Ts[0];
1: Ts extends [infer T1, ...infer TRest]
? DeepMerge<T1, DeepMergeAll<TRest, Options>, Options>
: Ts;
}[Ts extends readonly [any, any, ...any[]] ? 1 : 0];

type DeepMerge<T1, T2, Options extends deepmerge.Options> = IsSame<
T1,
Expand Down Expand Up @@ -52,22 +50,28 @@ type DeepMergeObjectProps<
[K in keyof T1]: Options["customMerge"] extends undefined
? DeepMerge<ValueOfKey<T1, K>, ValueOfKey<T2, K>, Options>
: ReturnType<NonNullable<Options["customMerge"]>> extends undefined
? DeepMerge<ValueOfKey<T1, K>, ValueOfKey<T2, K>, Options>
: ReturnType<NonNullable<ReturnType<NonNullable<Options["customMerge"]>>>>;
? DeepMerge<ValueOfKey<T1, K>, ValueOfKey<T2, K>, Options>
: ReturnType<
NonNullable<ReturnType<NonNullable<Options["customMerge"]>>>
>;
} &
{
[K in keyof T2]: Options["customMerge"] extends undefined
? DeepMerge<ValueOfKey<T1, K>, ValueOfKey<T2, K>, Options>
: ReturnType<NonNullable<Options["customMerge"]>> extends undefined
? DeepMerge<ValueOfKey<T1, K>, ValueOfKey<T2, K>, Options>
: ReturnType<NonNullable<ReturnType<NonNullable<Options["customMerge"]>>>>;
? DeepMerge<ValueOfKey<T1, K>, ValueOfKey<T2, K>, Options>
: ReturnType<
NonNullable<ReturnType<NonNullable<Options["customMerge"]>>>
>;
}
: {
[K in keyof (T1 & T2)]: Options["customMerge"] extends undefined
? DeepMerge<ValueOfKey<T1, K>, ValueOfKey<T2, K>, Options>
: ReturnType<NonNullable<Options["customMerge"]>> extends undefined
? DeepMerge<ValueOfKey<T1, K>, ValueOfKey<T2, K>, Options>
: ReturnType<NonNullable<ReturnType<NonNullable<Options["customMerge"]>>>>;
? DeepMerge<ValueOfKey<T1, K>, ValueOfKey<T2, K>, Options>
: ReturnType<
NonNullable<ReturnType<NonNullable<Options["customMerge"]>>>
>;
};

type DeepMergeArrays<
Expand Down Expand Up @@ -113,7 +117,9 @@ type ArrayMerge = (
type ObjectMerge = (
key: string,
options: Required<deepmerge.Options>
) => ((target: any, source: any, options?: deepmerge.Options) => any) | undefined;
) =>
| ((target: any, source: any, options?: deepmerge.Options) => any)
| undefined;

type IsMergeable = (value: any) => boolean;

Expand Down

0 comments on commit d409acd

Please sign in to comment.