Skip to content

Commit

Permalink
fix(ts): Fix type definition (#154)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mizunashi Mana authored and Ilya Radchenko committed Dec 8, 2016
1 parent 2c42001 commit fae53a1
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
declare namespace json2csv {
interface IField {
interface FieldValueCallback<T> {
(row: T, field: string, data: string): string;
}

interface FieldBase {
label?: string;
value: string;
default?: string;
}

interface IOptions {
data: any[];
fields?: (string | IField)[];
filedNames?: string[];
interface Field extends FieldBase {
value: string;
}

interface CallbackField<T> extends FieldBase {
value: FieldValueCallback<T>;
}

interface Options<T> {
data: T[];
fields?: (string | Field | CallbackField<T>)[];
fieldNames?: string[];
del?: string;
defaultValue?: string;
quotes?: string;
Expand All @@ -22,12 +33,14 @@ declare namespace json2csv {
includeEmptyRows?: boolean;
}

interface ICallback {
interface Callback {
(error: Error, csv: string): void;
}

export function json2csv(options: IOptions, callback: ICallback): void;
export function json2csv(options: IOptions): string;
}

export = json2csv.json2csv;
declare function json2csv<T>(options: json2csv.Options<T>, callback: json2csv.Callback): void;
declare function json2csv<T>(options: json2csv.Options<T>): string;
declare function json2csv(options: json2csv.Options<{ [key: string]: string; }>, callback: json2csv.Callback): void;
declare function json2csv(options: json2csv.Options<{ [key: string]: string; }>): string;

export = json2csv;

This comment has been minimized.

Copy link
@quantuminformation

quantuminformation Nov 15, 2017

why not es6 modules like
export default json2csv

Atm there is not import:
image
image

This comment has been minimized.

Copy link
@knownasilya

knownasilya Nov 15, 2017

Collaborator

If you can submit a PR that allows it and keeps the current ability, I'd merge that.

0 comments on commit fae53a1

Please sign in to comment.