From 1fbb7e68077b754bbd9b863936e12622d3a313fa Mon Sep 17 00:00:00 2001 From: Oleg S <97077423+RobotSail@users.noreply.github.com> Date: Thu, 2 Mar 2023 09:34:00 -0500 Subject: [PATCH] make sure undefined valeus are weeded out first Signed-off-by: Oleg S <97077423+RobotSail@users.noreply.github.com> --- packages/types/src/json.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/types/src/json.ts b/packages/types/src/json.ts index 4b0bb958ef..46b5cf9499 100644 --- a/packages/types/src/json.ts +++ b/packages/types/src/json.ts @@ -76,13 +76,6 @@ export const mergeJson = (a: JsonObject, b: JsonObject): JsonObject => { // for all primitives and arrays, we want to assign the value from b // for all objects, we want to recursively merge the values for (const key of intersectingKeys.values()) { - // check if value is an array or primitive - const value = b[key]; - if (Array.isArray(value) || typeof value !== 'object') { - final[key] = value; - continue; - } - // check if either value is undefined and default to the defined one const aValue = a[key]; const bValue = b[key]; @@ -95,6 +88,13 @@ export const mergeJson = (a: JsonObject, b: JsonObject): JsonObject => { continue; } + // check if value is an array or primitive + const value = bValue; + if (Array.isArray(value) || typeof value !== 'object') { + final[key] = value; + continue; + } + // recursively merge the values final[key] = mergeJson(aValue as JsonObject, bValue as JsonObject); }