DEPRECATED Check out: Khan Academy's Flow To Ts tool: https://github.com/khan/flow-to-ts
Converts flow files to ts using jscodeshift. It isn't perfect, but should get you pretty close. There are a couple of fundamental differences that have to be manually converted.
$ npx flow-to-ts -o ts /path/to/flow/files # Will convert .js files into .ts files
If you're going to be using this tool a couple of times, it's probably best not to use npx
since it will reinstall everything everytime you run it.
instead use npm install -g flow-to-ts
$ npx flow-to-ts -o tsx /path/to/flow/files # Will convert .js files into .tsx files
$ npx flow-to-ts -o tsx /path/to/flow/files # Will convert .jsx files into .tsx files
$ npx flow-to-ts -o d.ts /path/to/flow/files # Will convert .js.flow files into .d.ts files
Everything after -- will be forwarded to jscodeshift cli
$ npx flow-to-ts -o ts /path/to/flow/files -- --dry # Won't change code
In flow, definition files (.js.flow) are looked at with higher precedence over .js files. The reverse is true for typescript.
This is a problem if you do something like: "import {type Foo} from 'foo'" and there exists foo.js
and foo.js.flow
. You'll have to manually restructure your code.