From d409acdfeb3bf9cf2d65f8adc652aea5bfb6048f Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Tue, 10 Nov 2020 12:23:14 +1300 Subject: [PATCH] fix: use alternative DeepMergeAll approach to get around bad circular reference --- types/index.d.ts | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/types/index.d.ts b/types/index.d.ts index ad7040f..6a98659 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -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 - : unknown // DeepMerge, Options> - : T1 - : never; - +> = { + 0: Ts[0]; + 1: Ts extends [infer T1, ...infer TRest] + ? DeepMerge, Options> + : Ts; +}[Ts extends readonly [any, any, ...any[]] ? 1 : 0]; type DeepMerge = IsSame< T1, @@ -52,22 +50,28 @@ type DeepMergeObjectProps< [K in keyof T1]: Options["customMerge"] extends undefined ? DeepMerge, ValueOfKey, Options> : ReturnType> extends undefined - ? DeepMerge, ValueOfKey, Options> - : ReturnType>>>; + ? DeepMerge, ValueOfKey, Options> + : ReturnType< + NonNullable>> + >; } & { [K in keyof T2]: Options["customMerge"] extends undefined ? DeepMerge, ValueOfKey, Options> : ReturnType> extends undefined - ? DeepMerge, ValueOfKey, Options> - : ReturnType>>>; + ? DeepMerge, ValueOfKey, Options> + : ReturnType< + NonNullable>> + >; } : { [K in keyof (T1 & T2)]: Options["customMerge"] extends undefined ? DeepMerge, ValueOfKey, Options> : ReturnType> extends undefined - ? DeepMerge, ValueOfKey, Options> - : ReturnType>>>; + ? DeepMerge, ValueOfKey, Options> + : ReturnType< + NonNullable>> + >; }; type DeepMergeArrays< @@ -113,7 +117,9 @@ type ArrayMerge = ( type ObjectMerge = ( key: string, options: Required -) => ((target: any, source: any, options?: deepmerge.Options) => any) | undefined; +) => + | ((target: any, source: any, options?: deepmerge.Options) => any) + | undefined; type IsMergeable = (value: any) => boolean;