Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6211

Are there scripts or tools to help to migrate Flow to TypeScript automatically?

$
0
0

I have an old react-native module using Flow. There are several thousand lines of code. Now, I would like to migrate these codes to a new project using TypeScript. I am looking for an auto-tool to help me solve tedious type-converting works. If it would solve about 90% of problems, I would appreciate it. For example,

  • Changing all the .js file to 'ts or tsx file, like:
for f in `find . -type f -name '*.js'`;
do
git mv -- "$f""${f%.js}.ts"
done
  • convert types
// Flow
import type { Type1, Type2 } from ./dir/to/path
// Typescript
import { Type1, Type2 } from ./dir/to/path
// Flow
type Date = {
  toString: () => string,
  setTime: (time: number) => number
}

// TypeScript
interface Date {
  toString(): string;
  setTime(time: number): number;
}

// Flow 
value: ?string 
// TypeScript 
value: string | null

Any suggestions?


At last, I used flow-to-ts

yarn global add @khanacademy/flow-to-ts
flow-to-ts --write --delete-source ${myProjectPath}/src/**/**.js

There are other options:

Usage: flow-to-ts [options]

Options:
  -V, --version                    output the version number
  --inline-utility-types           inline utility types when possible, defaults to 'false'
  --prettier                       use prettier for formatting
  --semi                           add semi-colons, defaults to 'false' (depends on --prettier)
  --single-quote                   use single quotes instead of double quotes, defaults to 'false' (depends on --prettier)
  --tab-width [width]              size of tabs (depends on --prettier) (default: 4)
  --trailing-comma [all|es5|none]  where to put trailing commas (depends on --prettier) (default: "all")
  --bracket-spacing                put spaces between braces and contents, defaults to 'false' (depends on --prettier)
  --arrow-parens [avoid|always]    arrow function param list parens (depends on --prettier) (default: "avoid")
  --print-width [width]            line width (depends on --prettier) (default: 80)
  --write                          write output to disk instead of STDOUT
  --delete-source                  delete the source file
  -h, --help                       output usage information

Viewing all articles
Browse latest Browse all 6211

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>