Toolbox-XToolbox-X

Extract New Fields

Extracts only the new fields that exist in an updated object but not in a base object, recursively including nested fields.

extractNewFields

The extractNewFields function recursively compares an updated object with a base object and returns a new object containing only the fields that were introduced in the updated object.

Function Signature

function extractNewFields<T extends GenericObject, U extends GenericObject>(
  baseObject: T,
  updatedObject: U
): FlattenPartial<U>

Parameters

  • baseObject (T): The original object used as the baseline for comparison.
  • updatedObject (U): The new version of the object containing potential new fields.

Return Value

  • FlattenPartial<U>: A new object containing only the fields that did not exist in the baseObject.

Example Usage

playground.ts

Notes

  • This function does not detect changes in the values of existing keys; use extractUpdatedFields or extractUpdatedAndNewFields for that purpose.
  • 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)

On this page