From bd402d4157ad0e08cce42a28f2c859fc774e5bad Mon Sep 17 00:00:00 2001 From: Jack Date: Wed, 11 Apr 2018 03:28:26 +1000 Subject: [PATCH] fix(diff): update diffArrays return value type to support arrays (#24869) --- types/diff/diff-tests.ts | 12 ++++++++++-- types/diff/index.d.ts | 9 ++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/types/diff/diff-tests.ts b/types/diff/diff-tests.ts index f859a735b4..0dea2a305e 100644 --- a/types/diff/diff-tests.ts +++ b/types/diff/diff-tests.ts @@ -5,8 +5,16 @@ const other = 'beep boob blah'; let diff = jsdiff.diffChars(one, other); printDiff(diff); -diff = jsdiff.diffArrays(['a', 'b', 'c'], ['a', 'c', 'd']); -printDiff(diff); +const diffArraysResult = jsdiff.diffArrays(['a', 'b', 'c'], ['a', 'c', 'd']); +diffArraysResult.forEach(result => { + if (result.added) { + console.log(`added ${result.value.length} line(s):`, ...result.value); + } else if (result.removed) { + console.log(`removed ${result.value.length} line(s):`, ...result.value); + } else { + console.log(`no changes`); + } +}); // -------------------------- diff --git a/types/diff/index.d.ts b/types/diff/index.d.ts index 2017b43e0e..33d337d1b7 100644 --- a/types/diff/index.d.ts +++ b/types/diff/index.d.ts @@ -29,6 +29,13 @@ declare namespace JsDiff { removed?: boolean; } + interface IDiffArraysResult { + value: T[]; + count?: number; + added?: boolean; + removed?: boolean; + } + interface IBestPath { newPos: number; componenets: IDiffResult[]; @@ -85,7 +92,7 @@ declare namespace JsDiff { function diffSentences(oldStr: string, newStr: string, options?: IOptions): IDiffResult[]; - function diffArrays(oldArr: any[], newArr: any[], options?: IArrayOptions): IDiffResult[]; + function diffArrays(oldArr: T[], newArr: T[], options?: IArrayOptions): Array>; function createPatch(fileName: string, oldStr: string, newStr: string, oldHeader: string, newHeader: string, options?: {context: number}): string;