zemirco / json2csv

Convert json to csv with column titles
http://zemirco.github.io/json2csv
MIT License
2.72k stars 363 forks source link

Typescript help #272

Closed panteluke closed 6 years ago

panteluke commented 6 years ago

Just a small silly question, because I'm puzzled with the type definition. Can you give a simple example where you have an object of class A and you try to convert it to csv? I cannot figure out how you provide opts in the parser constructor.

juanjoDiaz commented 6 years ago

You can see some examples here: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/b0a6ea017ee6608093c073cbf7ce4ea84ddc0d9e/types/json2csv/json2csv-tests.ts

Can you elaborate a bit on what is unclear to you??

panteluke commented 6 years ago

Yes sure. In various examples we can see something like this:

const fields = [{
  label: 'Car Name',
  value: 'car'
},{
  label: 'Price USD',
  value: 'price'
}];

const json2csvParser = new Json2csvParser({ fields });

But I cannot figure out the way that I can achieve this through Typescript. Even in the link that you sent me, there is no such case if I'm not mistaken.

So, in your example, how can we set labels as "String", "Number", "Object" for example for interface ExampleObj?

juanjoDiaz commented 6 years ago

You are right. There is a bug in the Types but it should be fixed with my the PR I just made.

panteluke commented 6 years ago

Thank you