Extract Updated & New Fields
Identifies both changed and newly added fields between two objects, recursively including deep/nested changes.
extractUpdatedAndNewFields
The extractUpdatedAndNewFields function recursively compares an updated object with a base object and returns a new object containing both modified values and newly added fields.
Function Signature
function extractUpdatedAndNewFields<T extends GenericObject, U extends GenericObject>(
baseObject: T,
updatedObject: U
): FlattenPartial<T> & FlattenPartial<U>Parameters
baseObject(T): The original baseline reference object.updatedObject(U): The modified object containing potential updates and new fields.
Return Value
FlattenPartial<T> & FlattenPartial<U>: A combined object containing all updated values and new keys.
Example Usage
playground.ts
Notes
- Arrays: Arrays are treated as atomic values (not recursively diffed).
- Returns a new object without mutating either input.
Types
FlattenPartial<T>
type FlattenPartial<T> = Partial<{ [K in keyof T]: T[K] }>;Last updated: Sun, Jun 14, 2026 07:06:16AM (UTC)
