Skip to content

Commit c40c0d2

Browse files
authored
fix(csv-stringify): allow mixed string and object columns typedef (#456)
1 parent cc1235a commit c40c0d2

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

packages/csv-stringify/lib/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export interface Options extends stream.TransformOptions {
6161
* can refer to nested properties of the input JSON
6262
* see the "header" option on how to print columns names on the first line
6363
*/
64-
columns?: readonly string[] | PlainObject<string> | readonly ColumnOption[]
64+
columns?: ReadonlyArray<string | ColumnOption> | PlainObject<string>
6565
/**
6666
* Set the field delimiter, one character only, defaults to a comma.
6767
*/

packages/csv-stringify/test/api.types.sync.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe('API Types', () => {
2020
const rd: RecordDelimiter | undefined = options.record_delimiter
2121
const cast = options.cast
2222
const castBoolean : Cast<boolean> | undefined = cast?.boolean
23-
const columns: readonly string[] | PlainObject<string> | readonly ColumnOption[] | undefined = options.columns
23+
const columns: ReadonlyArray<string | ColumnOption> | PlainObject<string> | undefined = options.columns
2424
return [
2525
rd, castBoolean, columns
2626
]

packages/csv-stringify/test/api.types.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ describe('API Types', () => {
7070
{ key: 'b' },
7171
{ key: 'a' }
7272
]
73+
options.columns = [
74+
{ key: "b", header: "B" },
75+
{ key: "a" , header: "A" },
76+
"c",
77+
{ key: "d" },
78+
];
7379
options.columns = {
7480
field1: 'column1',
7581
field3: 'column3'
@@ -81,7 +87,7 @@ describe('API Types', () => {
8187
options.columns = ["b", "a"];
8288
options.columns = ["b", "a"] as const;
8389
});
84-
90+
8591
it('delimiter', () => {
8692
const options: Options = {}
8793
options.delimiter = ':'

0 commit comments

Comments
 (0)