Skip to content

Commit 5252b88

Browse files
committed
Improve declaration types for diffComm and merge APIs
closes #88
1 parent 45aefd4 commit 5252b88

1 file changed

Lines changed: 28 additions & 21 deletions

File tree

src/diff3.d.ts

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,15 @@ export interface ILCSResult {
1313
*/
1414
export function LCS<T>(buffer1: T[], buffer2: T[]): ILCSResult;
1515

16-
export interface ICommResult<T> {
16+
export type ICommResult<T> = {
17+
common: T[];
18+
buffer1?: never;
19+
buffer2?: never;
20+
} | {
21+
common?: never;
1722
buffer1: T[];
1823
buffer2: T[];
19-
}
24+
};
2025

2126
/**
2227
* We apply the LCS to build a 'comm'-style picture of the
@@ -124,16 +129,24 @@ export interface MergeRegion<T> {
124129
};
125130
}
126131

127-
export interface MergeResult {
132+
export interface MergeResult<T = string> {
128133
conflict: boolean;
129-
result: string[];
134+
result: Array<T | string>;
130135
}
131136

132137
export interface IMergeOptions {
133138
excludeFalseConflicts?: boolean;
134139
stringSeparator?: string | RegExp;
135140
}
136141

142+
export interface IMergeLabelOptions extends IMergeOptions {
143+
label?: {
144+
a?: string;
145+
o?: string;
146+
b?: string;
147+
};
148+
}
149+
137150
/**
138151
* Applies the output of diff3MergeRegions to actually
139152
* construct the merged buffer; the returned result alternates
@@ -146,36 +159,30 @@ export interface IMergeOptions {
146159
* @param {{excludeFalseConflicts: boolean; stringSeparator: RegExp}} options
147160
* @returns {MergeRegion<T>[]}
148161
*/
149-
export function diff3Merge<T>(
162+
export function diff3Merge<T = string>(
150163
a: string | T[],
151164
o: string | T[],
152165
b: string | T[],
153166
options?: IMergeOptions
154167
): MergeRegion<T>[];
155168

156-
export function merge<T>(
169+
export function merge<T = string>(
157170
a: string | T[],
158171
o: string | T[],
159172
b: string | T[],
160-
options?: IMergeOptions
161-
): MergeResult;
173+
options?: IMergeLabelOptions
174+
): MergeResult<T>;
162175

163-
export function mergeDiff3<T>(
176+
export function mergeDiff3<T = string>(
164177
a: string | T[],
165178
o: string | T[],
166179
b: string | T[],
167-
options?: IMergeOptions & {
168-
label?: {
169-
a?: string;
170-
o?: string;
171-
b?: string;
172-
}
173-
}
174-
): MergeResult;
175-
176-
export function mergeDigIn<T>(
180+
options?: IMergeLabelOptions
181+
): MergeResult<T>;
182+
183+
export function mergeDigIn<T = string>(
177184
a: string | T[],
178185
o: string | T[],
179186
b: string | T[],
180-
options?: IMergeOptions
181-
): MergeResult;
187+
options?: IMergeLabelOptions
188+
): MergeResult<T>;

0 commit comments

Comments
 (0)