Skip to content

fix(csv-stringify): allow mixed string and object columns typedef #456

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/csv-stringify/lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export interface Options extends stream.TransformOptions {
* can refer to nested properties of the input JSON
* see the "header" option on how to print columns names on the first line
*/
columns?: readonly string[] | PlainObject<string> | readonly ColumnOption[]
columns?: ReadonlyArray<string | ColumnOption> | PlainObject<string>
/**
* Set the field delimiter, one character only, defaults to a comma.
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/csv-stringify/test/api.types.sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('API Types', () => {
const rd: RecordDelimiter | undefined = options.record_delimiter
const cast = options.cast
const castBoolean : Cast<boolean> | undefined = cast?.boolean
const columns: readonly string[] | PlainObject<string> | readonly ColumnOption[] | undefined = options.columns
const columns: ReadonlyArray<string | ColumnOption> | PlainObject<string> | undefined = options.columns
return [
rd, castBoolean, columns
]
Expand Down
8 changes: 7 additions & 1 deletion packages/csv-stringify/test/api.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ describe('API Types', () => {
{ key: 'b' },
{ key: 'a' }
]
options.columns = [
{ key: "b", header: "B" },
{ key: "a" , header: "A" },
"c",
{ key: "d" },
];
options.columns = {
field1: 'column1',
field3: 'column3'
Expand All @@ -81,7 +87,7 @@ describe('API Types', () => {
options.columns = ["b", "a"];
options.columns = ["b", "a"] as const;
});

it('delimiter', () => {
const options: Options = {}
options.delimiter = ':'
Expand Down