export function mergeWithNoUndefined< S extends Record, A extends Record, >(source: S, add: A) { const addKeys = Object.keys(add) as (keyof A)[]; const addNonUndefinedKeys = addKeys.filter((key) => add[key] !== undefined); const newAdd = addNonUndefinedKeys.reduce( (acc, key) => { acc[key] = add[key]; return acc; }, {} as Record, ); return { ...source, ...newAdd, }; }