From 71b28b81e3c18c054943cfdfe414d6390e9c36bf Mon Sep 17 00:00:00 2001 From: Nikolay Date: Fri, 12 Jul 2019 17:24:05 +1000 Subject: [PATCH] Typescript definitions --- index.d.ts | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) 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