diff --git a/index.d.ts b/index.d.ts index 2fea20a..b8a96da 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,15 +1,44 @@ -export function diff (originalObj: object, updatedObj: object): object +type Primitive = string | number | boolean | null | undefined; -export function addedDiff (originalObj: object, updatedObj: object): object +export type Diff = T extends Primitive + ? T + : T extends Array + ? { [key: string]: Diff } + : { [P in keyof T]?: Diff }; -export function deletedDiff (originalObj: object, updatedObj: object): object +export type DiffRemovable = T extends Primitive + ? T + : T extends Array + ? { [key: string]: DiffRemovable } + : { [P in keyof T]?: DiffRemovable }; -export function updatedDiff (originalObj: object, updatedObj: object): object +export function diff( + originalObj: T, + updatedObj: T, +): DiffRemovable; -export interface DetailedDiff { - added: object - deleted: object - updated: object -} +export function addedDiff( + originalObj: T, + updatedObj: T, +): Diff; -export function detailedDiff (originalObj: object, updatedObj: object): DetailedDiff +export function deletedDiff( + originalObj: T, + updatedObj: T, +): DiffRemovable; + +export function updatedDiff( + originalObj: T, + updatedObj: T, +): Diff; + +export type DetailedDiff = { + added: Diff; + deleted: DiffRemovable; + updated: Diff; +}; + +export function detailedDiff( + originalObj: T, + updatedObj: T, +): DetailedDiff;