Build a minimal PATCH payload
Compare JSON-like records deeply and emit only fields whose values changed.Description
Requirements
Export a generic buildPatch function from src/App.tsx.
Include a current own field only when it is not deeply equal to the original value.
Include fields owned only by current with their current values, including explicit undefined.
Omit primitive and nested values that are deeply equal.
Represent an original own key missing from current as an own patch key set to undefined.
Compare JSON-like arrays and plain objects recursively rather than by reference.
Return a new patch object on every call, including when no fields changed.
Preserve T in the public signature and return Partial<T> without widening field names.
Do not mutate either source object or any nested input value.
One changed field
original {title:'A',meta:{pages:2}}, current {title:'B',meta:{pages:2}}{title:'B'}Deep-equal nested values are omitted even when their object identity differs.
Deleted field
original owns description; current does not
The patch owns description with value undefined
An own undefined key distinguishes deletion from an unchanged omission.
Constraints
Compare enumerable own string keys onlySupport JSON primitives, arrays, plain objects, and undefinedArray order is significant
Hints
Hint 1
Iterate the union of Object.keys from both records.
Hint 2
Use hasOwnProperty checks before comparing values so absence differs from owned undefined.
Hint 3
Keep the recursive equality helper side-effect free and treat arrays separately from objects.