是否有脚本或工具可以帮助将流自动迁移到TypeScript?
我有一个使用流的旧react本机模块。有几千行代码。现在,我想使用TypeScript将这些代码迁移到一个新项目中。我正在寻找一个自动工具,以帮助我解决繁琐的类型转换工作。如果它能解决大约90%的问题,我将不胜感激。 比如说,是否有脚本或工具可以帮助将流自动迁移到TypeScript?,typescript,react-native,flowtype,migrate,Typescript,React Native,Flowtype,Migrate,我有一个使用流的旧react本机模块。有几千行代码。现在,我想使用TypeScript将这些代码迁移到一个新项目中。我正在寻找一个自动工具,以帮助我解决繁琐的类型转换工作。如果它能解决大约90%的问题,我将不胜感激。 比如说, 将所有.js文件更改为'ts或tsx文件,如: 转换类型 有什么建议吗 最后,我用 还有其他选择: Usage: flow-to-ts [options] Options: -V, --version output t
- 将所有
文件更改为'.js
或ts
文件,如:tsx
- 转换类型
最后,我用 还有其他选择:
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
你试过了吗?嗨,我用过了。有一个错误<代码>错误:EISDIR:目录上的非法操作,在cli.js:79:23的Object.readSync(fs.js:498:3)处读取。我应该使用文件globs,而不是目录路径。
// 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
yarn global add @khanacademy/flow-to-ts
flow-to-ts --write --delete-source ${myProjectPath}/src/**/**.js
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