diff --git a/index.d.ts b/index.d.ts index e848bff..4b62032 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,9 +1,37 @@ -export function diff (originalObj: object, updatedObj: object): object +type DeepPartial = { + [K in keyof T]?: DeepPartial +} -export function addedDiff (originalObj: object, updatedObj: object): object +interface IDictionary { + [key: string]: T; +} -export function deletedDiff (originalObj: object, updatedObj: object): object +/* + In "deep-object-diff" there're 2 scenarios for a property diff: + 1. If the property is an object or primitive, the diff is a deep partial; + 2. If the property is an array, the diff is a dictionary. + Its keys are indices, and the values are deep partials of the change. +*/ +type PropertyDiff = T extends Array + ? IDictionary + : DeepPartial; -export function updatedDiff (originalObj: object, updatedObj: object): object +export type Diff = { + [P in keyof T]?: PropertyDiff; +}; -export function detailedDiff (originalObj: object, updatedObj: object): object +export interface IDetailedDiff { + added: Diff; + deleted: Diff; + updated: Diff; +} + +export function diff (originalObj: T, updatedObj: T): Diff + +export function addedDiff (originalObj: T, updatedObj: T): Diff + +export function deletedDiff (originalObj: T, updatedObj: T): Diff + +export function updatedDiff (originalObj: T, updatedObj: T): Diff + +export function detailedDiff (originalObj: T, updatedObj: T): IDetailedDiff