Extract Updated Fields
Extracts only the fields that have changed between two objects, recursively including deep/nested changes.
extractUpdatedFields
The extractUpdatedFields function recursively compares an updated object with a base object and returns a new object containing only the fields whose values have changed.
Function Signature
function extractUpdatedFields<T extends GenericObject>(
baseObject: T,
updatedObject: FlattenPartial<T>
): FlattenPartial<T>Parameters
baseObject(T): The original reference object.updatedObject(FlattenPartial<T>): An object containing potential updates for fields of the base object.
Return Value
FlattenPartial<T>: A new object containing only the properties that have changed values.
Example Usage
playground.ts
Notes
- This function does not detect newly added keys (use
extractNewFieldsorextractUpdatedAndNewFieldsfor that). - Arrays are treated as atomic values; their items are 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)
