How to add flow and typescript typings to NPM module

785 Views Asked by At

Is there a guide how to add flow and typescript typings to NPM module simultaneously.

I can not find a good guide and it is common problem for open source libraries that in issues people ask for adding typings.

1

There are 1 best solutions below

0
On BEST ANSWER

The simple answer, right now seem there are no ready to use solutions. When you are creating a lib and you are exporting your module with index.js for example you can add index.d.ts and index.js.flow and it will work.

If you already using for you lib types the process of creating definition can be very enoying, luckily there are some good people on it. Flow already have flow gen-flow-files, still not release under stable. For typescript, I don't know if there is something similar, but TS more mature I hope they did something.

Now the other painful process, you got one of the definitions you want to convert it to the other one. If you write you definition in TS there are few choices for you to convert it to flow (I don't have any experience with any of them). But if you writing with flow, I didn't find anything that allows you to covert it to TS.

I have started to create a boilerplate and playground focus on this specific problem. https://github.com/idanilt/flow_ts_lib

Right now this solution fit my needs, write flow lib and support TS and flow application (I convert flow to TS with very simple regex). But I want to added to it as many cases as I can, so anybody want to write a lib will not need to face this issue again.