0

I want to use the neat-csv library but it does not provide a typescript definition file. Several blogs mentioned a quick way to create a minimal definition file to get started:

declare var neatCsv: any; 

But I don't know what to do with the definition file. Where should it be located? How do you link the definition file with the actual implementation which is located in node_modules/neat-csv. Then how do you import it in an actual typescript file?

1 Answer 1

1

The package used the following module import syntax:

const neatCsv = require('neat-csv'); 

This means that the kind of module is that you need don't use exports { x } of default exports export default x. What you need is the following:

declare module "neat-csv" { var neatCsv: (input: any, options?: any) => Promise<any>; export = neatCsv; } 

You can copy the preceding code in a file named declarations.d.ts inside your src folder. Then, you will be able to import it and use it as follows:

import * as neatCsv from "neat-csv"; let csv = "type,part\nunicorn,horn\nrainbow,pink"; neatCsv(csv, { /* options */ }); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.