Files
DefinitelyTyped/types/convert-array-to-csv/convert-array-to-csv-tests.ts
Alan ef830fd355 🤖 Merge PR #61079 Add type for convert-array-to-csv by @Qiming-Liu
* Add type for convert-array-to-csv

* Add specific test
2022-07-04 14:03:28 -07:00

43 lines
914 B
TypeScript

import { convertArrayToCSV } from 'convert-array-to-csv';
const header = ['number', 'first', 'last', 'handle'];
const dataArrays = [
[1, 'Mark', 'Otto', '@mdo'],
[2, 'Jacob', 'Thornton', '@fat'],
[3, 'Larry', 'the Bird', '@twitter'],
];
const dataObjects = [
{
number: 1,
first: 'Mark',
last: 'Otto',
handle: '@mdo',
},
{
number: 2,
first: 'Jacob',
last: 'Thornton',
handle: '@fat',
},
{
number: 3,
first: 'Larry',
last: 'the Bird',
handle: '@twitter',
},
];
// $ExpectType string
const csvFromArrayOfObjects = convertArrayToCSV(dataObjects);
// $ExpectType string
const csvFromArrayOfArrays = convertArrayToCSV(dataArrays, {
header,
separator: ';',
});
// When the param is incorrect
// @ts-expect-error
const csvFromString = convertArrayToCSV('1, Mark, Otto, @mdo');