Giter VIP home page Giter VIP logo

flow2typescript's Introduction

flow2typescript

Convert Flow source code to TypeScript

Status

Experimental; but pretty advanced. Should save you significant time, but you'll still need to do some things manually.

Targetted at backend code; has not been tested against frontend code (React/Vue/etc).

Issue Policy

Hi, I'm @Benjie, an independent open source developer. My open source work is funded by community sponsorship and client work. This is not one of my core projects, so unless you sponsor me or work on one of the open source projects I am involved with or rely on then your feature requests may be closed unless they come with an accompanying offer to send a PR.

If your company needs a particular feature, or a particular codebase converted, please get in touch and we can discuss a fee for the work.

If you need to discuss your migration strategy, you can book an hour of screen-sharing with @Benjie.

Usage

Install this module globally:

npm install -g flow2typescript
# or
yarn global add flow2typescript

And then run it:

flow2typescript path/to/file.flow.js

The above will output the converted code to stdout.

We can also write the file for you, using one of the following equivalent syntaxes:

flow2typescript path/to/file.flow.js path/to/file.ts
flow2typescript -i path/to/file.flow.js -o path/to/file.ts
flow2typescript --input path/to/file.flow.js --output path/to/file.ts

After running the conversion, I highly recommend that you run prettier against the resulting code, as the indentation can be quite problematic otherwise.

Programmatic

import { compile } from 'flow2typescript'
import { readFileSync, writeFileSync } from 'fs'

let path = 'path/to/file.js.flow'
let file = readFileSync(path, 'utf-8')

compile(file, path).then(ts => writeFileSync('path/to/file.ts', ts))

Credits

This project is a fork of bcherny/flow-to-typescript which diverged too far for the pull request to be merged.

Huge props to @bcherny for the original heroic effort on this project!

flow2typescript's People

Contributors

benjie avatar bcherny avatar dependabot[bot] avatar alexanderchan avatar lgarron avatar

Stargazers

Aaron Gray avatar  avatar Patrick Wozniak avatar Aleks avatar Daniel Georgiev avatar Kyle Peeler avatar Andrés avatar Eric Hartline avatar  avatar Joe Bowbeer avatar  avatar  avatar Andrejs Agejevs avatar Jessica Stokes avatar lake.zero(레이크/한영수) avatar Xavier Carpentier avatar Omar Jbara avatar Sibelius Seraphini avatar Bazyli Brzóska avatar Emmanuel Haguet avatar Dennis Torres avatar

Watchers

Aaron Gray avatar  avatar Dennis Torres avatar James Cloos avatar Kyle Peeler avatar  avatar

flow2typescript's Issues

Spurious newlines

Due to the way that @babel/generator works, various closing parentheses and braces are placed on the previous line, and then retainLines causes us to skip the line that had the closing parentheses, meaning that after prettier is ran there's additional linebreaks than before. I'm raising a PR to Babel to address this.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.