mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-06-05 20:02:05 +08:00
fix(diff): update diffArrays return value type to support arrays (#24869)
This commit is contained in:
@@ -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<string>(['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`);
|
||||
}
|
||||
});
|
||||
|
||||
// --------------------------
|
||||
|
||||
|
||||
9
types/diff/index.d.ts
vendored
9
types/diff/index.d.ts
vendored
@@ -29,6 +29,13 @@ declare namespace JsDiff {
|
||||
removed?: boolean;
|
||||
}
|
||||
|
||||
interface IDiffArraysResult<T> {
|
||||
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<T>(oldArr: T[], newArr: T[], options?: IArrayOptions): Array<IDiffArraysResult<T>>;
|
||||
|
||||
function createPatch(fileName: string, oldStr: string, newStr: string, oldHeader: string, newHeader: string, options?: {context: number}): string;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user