diff --git a/lib/utils.ts b/lib/utils.ts index de82315bf..36d9226aa 100644 --- a/lib/utils.ts +++ b/lib/utils.ts @@ -106,12 +106,34 @@ function fastMerge(target: TValue, source: TValue, shouldRemoveNestedNul /** Deep removes the nested null values from the given value. */ function removeNestedNullValues | null>(value: TValue): TValue { - if (typeof value === 'object' && !Array.isArray(value)) { - const objectValue = value as Record; - return fastMerge(objectValue, objectValue) as TValue; + if (value === null || value === undefined) { + return value; } - return value; + if (typeof value !== 'object' || Array.isArray(value)) { + return value; + } + + const result: Record = {}; + + // eslint-disable-next-line no-restricted-syntax, guard-for-in + for (const key in value) { + const propertyValue = value[key]; + + if (propertyValue === null || propertyValue === undefined) { + // eslint-disable-next-line no-continue + continue; + } + + if (typeof propertyValue === 'object' && !Array.isArray(propertyValue)) { + const valueWithoutNestedNulls = removeNestedNullValues(propertyValue); + result[key] = valueWithoutNestedNulls; + } else { + result[key] = propertyValue; + } + } + + return result as TValue; } /** Formats the action name by uppercasing and adding the key if provided. */