diff --git a/types/deep-diff/deep-diff-tests.ts b/types/deep-diff/deep-diff-tests.ts index 73c49b4d42..6192dad9e5 100644 --- a/types/deep-diff/deep-diff-tests.ts +++ b/types/deep-diff/deep-diff-tests.ts @@ -1,5 +1,4 @@ -import _deepDiff = require('deep-diff'); -const diff = _deepDiff.diff; +import { diff, observableDiff, applyChange, Diff } from 'deep-diff'; let lhs = { name: 'my object', @@ -21,15 +20,12 @@ let rhs = { } }; -const differences: Array> = diff(lhs, rhs); +const differences: Array> = diff(lhs, rhs); console.log(differences); // -------------------------- -const observableDiff = _deepDiff.observableDiff; -const applyChange = _deepDiff.applyChange; - lhs = { name: 'my object', description: 'it\'s an object!', diff --git a/types/deep-diff/index.d.ts b/types/deep-diff/index.d.ts index e83e0592e4..c246e42501 100644 --- a/types/deep-diff/index.d.ts +++ b/types/deep-diff/index.d.ts @@ -1,79 +1,60 @@ -// Type definitions for deep-diff 1.0.2 +// Type definitions for deep-diff 1.0 // Project: https://github.com/flitbit/diff/ // Definitions by: ZauberNerd // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 -declare namespace deepDiff { - - interface DiffNew { - kind: Kind; - path?: any[]; - rhs: RHS; - } - - interface DiffDeleted { - kind: Kind; - path?: any[]; - lhs: LHS; - } - - interface DiffEdit { - kind: Kind; - path?: any[]; - lhs: LHS; - rhs: RHS; - } - - interface DiffArray { - kind: Kind; - path?: any[]; - index: number; - item: Diff; - } - - type Diff = DiffNew | DiffDeleted | DiffEdit | DiffArray; - - interface PreFilterFunction { - (path: any[], key: any): boolean; - } - interface PreFilterObject { - prefilter?(path: any[], key: any): boolean; - normalize?(currentPath: any, key: any, lhs: LHS, rhs: RHS): [ LHS, RHS ] | undefined; - } - type PreFilter = PreFilterFunction | PreFilterObject; - - interface Accumulator { - push(diff: Diff): void; - length: number; - } - - interface Observer { - (diff: Diff): void; - } - - interface Filter { - (target: LHS, source: RHS, change: Diff): boolean; - } - - interface DeepDiff { - diff(lhs: LHS, rhs: RHS, prefilter?: PreFilter): Diff[] | undefined; - diff(lhs: LHS, rhs: RHS, prefilter?: PreFilter, acc?: Accumulator): Accumulator; - orderIndependentDiff: typeof DeepDiff.diff; - observableDiff(lhs: LHS, rhs: RHS, observer?: Observer, prefilter?: PreFilter, orderIndependent?: boolean): Diff[]; - orderIndependentDeepDiff(lhs: LHS, rhs: RHS, changes: Diff[], prefilter: PreFilter, path: any[], key: any, stack: any[]): void; - orderIndepHash(object: any): number; - applyDiff(target: LHS, source: RHS, filter?: Filter): void; - applyChange(target: LHS, source: any, change: Diff): void; - revertChange(target: LHS, source: any, change: Diff): void; - isConflict(): boolean; - noConflict(): DeepDiff; - } +export interface DiffNew { + kind: Kind; + path?: any[]; + rhs: RHS; } -declare var DeepDiff: deepDiff.DeepDiff; - -declare module "deep-diff" { - var diff: deepDiff.DeepDiff; - export = diff; +export interface DiffDeleted { + kind: Kind; + path?: any[]; + lhs: LHS; } + +export interface DiffEdit { + kind: Kind; + path?: any[]; + lhs: LHS; + rhs: RHS; +} + +export interface DiffArray { + kind: Kind; + path?: any[]; + index: number; + item: Diff; +} + +export type Diff = DiffNew | DiffDeleted | DiffEdit | DiffArray; + +export type PreFilterFunction = (path: any[], key: any) => boolean; +export interface PreFilterObject { + prefilter?(path: any[], key: any): boolean; + normalize?(currentPath: any, key: any, lhs: LHS, rhs: RHS): [ LHS, RHS ] | undefined; +} +export type PreFilter = PreFilterFunction | PreFilterObject; + +export interface Accumulator { + push(diff: Diff): void; + length: number; +} + +export type Observer = (diff: Diff) => void; + +export type Filter = (target: LHS, source: RHS, change: Diff) => boolean; + +export function diff(lhs: LHS, rhs: RHS, prefilter?: PreFilter): Array> | undefined; +export function diff(lhs: LHS, rhs: RHS, prefilter?: PreFilter, acc?: Accumulator): Accumulator; +export function orderIndependentDiff(lhs: LHS, rhs: RHS, prefilter?: PreFilter): Array> | undefined; +export function orderIndependentDiff(lhs: LHS, rhs: RHS, prefilter?: PreFilter, acc?: Accumulator): Accumulator; +export function observableDiff(lhs: LHS, rhs: RHS, observer?: Observer, prefilter?: PreFilter, orderIndependent?: boolean): Array>; +export function orderIndependentDeepDiff(lhs: LHS, rhs: RHS, changes: Array>, prefilter: PreFilter, path: any[], key: any, stack: any[]): void; +export function orderIndepHash(object: any): number; +export function applyDiff(target: LHS, source: RHS, filter?: Filter): void; +export function applyChange(target: LHS, source: any, change: Diff): void; +export function revertChange(target: LHS, source: any, change: Diff): void;