flow-to-typescript icon indicating copy to clipboard operation
flow-to-typescript copied to clipboard

Continued development / support

Open jthegedus opened this issue 6 years ago • 6 comments

This tool looks to be extremely useful and I was wondering if you personally intend to work on this further? Although I know nothing about how it works, I would certainly be open to contributing supposing PRs would be merged etc. I see great use for this tool in bridging the Flow/TS world :smiley:

jthegedus avatar Mar 04 '18 13:03 jthegedus

Hey, thanks @jthegedus! I do, but it's on my back burner. I started working on this, then realized two things:

  1. The babel-types typings are really incomplete and inaccurate. I fixed this by codegen'ing TypeScript typings in babel-types itself, to guarantee that types are complete and accurate. This is now merged into babel, making the work for flow-to-ts significantly easier.
  2. A walker pattern isn't adequate for converting an AST from Flow -> TS, because once you convert a node, you also have to convert all of its descendants. A walker is great for terminal nodes, but doesn't work well elsewhere. So I began workin on the https://github.com/bcherny/flow-to-typescript/tree/recursive-descent branch, which walks the Flow AST nodes with a basic depth first traversal to convert them to TS.

The remaining work is for (2) in the branch I linked, to make sure all types of nodes are covered, and are mapped to their TS counterparts. Luckily TS's completeness checking for unions will warn us if we're missing anything.

Contributions are welcome, otherwise I'll get back to this sometime. Feel free to fork the recursive-descent branch if you like.

bcherny avatar Mar 04 '18 19:03 bcherny

This project is super exciting! I Check out recast. It's an AST parser and it may help you traverse while you do the Flow -> TS conversion.

evans avatar Mar 19 '18 17:03 evans

I suspect using babel traverse could be helpful, except that the declarations are out of date!

I've been looking into doing TS declarations for babel 7, ironically found this library while looking for options for reducing the burden of keeping them up to date, since the babel source code uses flow already.

simonbuchan avatar Apr 17 '18 22:04 simonbuchan

I have some interest in chipping in but none of the branches I've checked out are compiling right now. What exactly is the state of repo's code?

jack-guy avatar Mar 28 '19 19:03 jack-guy

@jack-guy It's still very much pre-alpha. It's not really 'useable' right now so much as 'developable'.

If you have a pressing need to convert some Flow code you might be best off writing your own one-off converter using this project as a (very helpful) example, and just implementing the bits you need.

jbreckmckye avatar Jun 13 '19 11:06 jbreckmckye

FYI: Seems there is another project with the similar functionality https://github.com/Kiikurage/babel-plugin-flow-to-typescript#readme

miso-belica avatar Jun 13 '19 14:06 miso-belica