Skip to content

Commit fae53a1

Browse files
Mizunashi ManaIlya Radchenko
authored andcommitted
fix(ts): Fix type definition (#154)
1 parent 2c42001 commit fae53a1

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

index.d.ts

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
11
declare namespace json2csv {
2-
interface IField {
2+
interface FieldValueCallback<T> {
3+
(row: T, field: string, data: string): string;
4+
}
5+
6+
interface FieldBase {
37
label?: string;
4-
value: string;
58
default?: string;
69
}
710

8-
interface IOptions {
9-
data: any[];
10-
fields?: (string | IField)[];
11-
filedNames?: string[];
11+
interface Field extends FieldBase {
12+
value: string;
13+
}
14+
15+
interface CallbackField<T> extends FieldBase {
16+
value: FieldValueCallback<T>;
17+
}
18+
19+
interface Options<T> {
20+
data: T[];
21+
fields?: (string | Field | CallbackField<T>)[];
22+
fieldNames?: string[];
1223
del?: string;
1324
defaultValue?: string;
1425
quotes?: string;
@@ -22,12 +33,14 @@ declare namespace json2csv {
2233
includeEmptyRows?: boolean;
2334
}
2435

25-
interface ICallback {
36+
interface Callback {
2637
(error: Error, csv: string): void;
2738
}
28-
29-
export function json2csv(options: IOptions, callback: ICallback): void;
30-
export function json2csv(options: IOptions): string;
3139
}
3240

33-
export = json2csv.json2csv;
41+
declare function json2csv<T>(options: json2csv.Options<T>, callback: json2csv.Callback): void;
42+
declare function json2csv<T>(options: json2csv.Options<T>): string;
43+
declare function json2csv(options: json2csv.Options<{ [key: string]: string; }>, callback: json2csv.Callback): void;
44+
declare function json2csv(options: json2csv.Options<{ [key: string]: string; }>): string;
45+
46+
export = json2csv;

0 commit comments

Comments
 (0)