I am trying to parse a csv file with typescript which I am totally new to. I cannot get the parser working with the correct typings.
Without typings everything is easy:
var fs = require('fs');
var parse = require('csv-parse');
var parser = parse({delimiter: ';'}, function(err, data){
console.log(data);
});
fs.createReadStream(__dirname+'/fs_read.csv').pipe(parser);
But when it comes to typescript I get errors, I installed the typings from dt :
import * as csvParse from 'csv-parse';
import fs = require('fs');
var myParser:csvParse.CsvParser = csvParse({delimiter: ','}, function(data, err) {
console.log(data);
});
I get the error
Type 'void | CsvParser' is not assignable to type 'CsvParser'.
Can anyone give me a hint or used csv-parse with typescript before and share their code?
csvParse({delimiter: ','}, function(data, err)....?class myparser implements csvParse.CsvParserBut then I could not get the parsed datanew csvParse.CsvParse({delimiter: ','}, function(data, err)....Only a void function can be called with the 'new' keywordparsein line 3 withparse.parse