Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/MarcoPolo/flowToTs
Flow to Typescript codemod
https://github.com/MarcoPolo/flowToTs
codemod flowtype typescript
Last synced: 3 months ago
JSON representation
Flow to Typescript codemod
- Host: GitHub
- URL: https://github.com/MarcoPolo/flowToTs
- Owner: MarcoPolo
- Created: 2019-03-09T15:28:28.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2019-10-29T13:34:47.000Z (over 5 years ago)
- Last Synced: 2024-10-26T07:37:10.607Z (4 months ago)
- Topics: codemod, flowtype, typescript
- Language: TypeScript
- Size: 305 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-codemods - flowToTs - Flow to Typescript codemods. (Typescript)
README
# DEPRECATED Check out: Khan Academy's Flow To Ts tool: https://github.com/khan/flow-to-ts
# Intro
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.
# Usage
```
$ 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](https://github.com/zkat/npx/issues/113) you run it.
instead use `npm install -g flow-to-ts`
## Advanced Usage
### .js files with jsx
```
$ npx flow-to-ts -o tsx /path/to/flow/files # Will convert .js files into .tsx files
```### .jsx files
```
$ npx flow-to-ts -o tsx /path/to/flow/files # Will convert .jsx files into .tsx files
```### .js.flow files
```
$ npx flow-to-ts -o d.ts /path/to/flow/files # Will convert .js.flow files into .d.ts files
```### Dry Mode and passing arguments to jscodeshift
Everything after -- will be forwarded to jscodeshift cli
```
$ npx flow-to-ts -o ts /path/to/flow/files -- --dry # Won't change code
```## Fundamental Differences
### .js.flow vs .d.ts
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.