Skip to content

Commit a52abc4

Browse files
committed
fix(csv-stringify): allow mixed string and object columns typedef
1 parent cc1235a commit a52abc4

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
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: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,16 @@ describe('API Types', () => {
8181
options.columns = ["b", "a"];
8282
options.columns = ["b", "a"] as const;
8383
});
84+
85+
it("colummns as mixed strings and objects", () => {
86+
const options: Options = {};
87+
options.columns = [
88+
{ key: "b", header: "B" },
89+
{ key: "a" , header: "A" },
90+
"c",
91+
{ key: "d" },
92+
];
93+
})
8494

8595
it('delimiter', () => {
8696
const options: Options = {}

0 commit comments

Comments
 (0)