https://github.com/burnnat/flow-to-dts
Convert Flow libdef files to Typescript .d.ts definitions.
https://github.com/burnnat/flow-to-dts
babel-plugin flowtype typescript
Last synced: 30 days ago
JSON representation
Convert Flow libdef files to Typescript .d.ts definitions.
- Host: GitHub
- URL: https://github.com/burnnat/flow-to-dts
- Owner: burnnat
- License: mit
- Created: 2018-06-16T13:46:30.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-03-02T12:44:58.000Z (over 6 years ago)
- Last Synced: 2025-04-20T02:36:56.647Z (about 2 months ago)
- Topics: babel-plugin, flowtype, typescript
- Language: TypeScript
- Size: 192 KB
- Stars: 10
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-list - flow-to-dts
README
# flow-to-dts
[](https://www.npmjs.com/package/flow-to-dts) [](https://travis-ci.org/burnnat/flow-to-dts) [](https://coveralls.io/github/burnnat/flow-to-dts?branch=master)Convert [Flow libdefs](https://flow.org/en/docs/libdefs/) to [Typescript declaration files](https://www.typescriptlang.org/docs/handbook/declaration-files/introduction.html).
**This tool is currently pre-alpha.** Contribution of issues, suggesions, and pull requests are welcome!
# Usage
## Command Line
```
flow-to-dts input.flow.js output.d.ts
```## Node API
Transforming a code string:
```js
import { transform } from 'flow-to-dts';const input = 'type MyCode';
transform(input).then((output) => console.log(output));
```Transforming an AST:
```js
import { parse } from '@babel/parser';
import { transformAst } from 'flow-to-dts';const input = parse('type MyCode');
transformAst(input).then((output) => console.log(JSON.stringify(output)));
```# Supported Features
(Note that this is not intended as an exhaustive list, but merely a representative sample indicating some of the key transformations performed by the tool.)| Feature | Supported | Flow | Typescript |
|------------------|--------------------|-------------------------------------|---------------------------------------------------|
| Flow Header | :heavy_check_mark: | `// @flow` | `// ` |
| Module Exports | :heavy_check_mark: | `declare module.exports: MyModule;` | `export = MyModule;` |
| Mixed Type | :heavy_check_mark: | `mixed` | `number \| string \| boolean \| symbol \| object` |
| Nullable Types | :heavy_check_mark: | `?string` | `string \| null \| undefined` |
| Tuple Types | :heavy_check_mark: | `[number, string]` | `[number, string]` |
| Exact Objects | :heavy_check_mark: | `{\| name: string \|}` | `{ name: string }` |
| Open Objects | :heavy_check_mark: | `{ name: string }` | `{ name: string; [field: string]: any }` |
| Class Types | :heavy_check_mark: | `Class` | `typeof SomeType` |
| Built-in Types | :heavy_check_mark: | `http$ClientRequest` | `import { ClientRequest } from "http";` |
| Key Types | :x: | `$Keys` | |
| Value Types | :x: | `$Values` | |
| Difference Types | :x: | `$Diff` | |
| Partial Types | :heavy_check_mark: | `$Shape` | `Partial` |
| Rest Types | :x: | `$Rest` | |
| Supertypes | :x: | `$Supertype` | |
| Subtypes | :x: | `$Subtype` | |
| Existential Type | :heavy_check_mark: | `*` | `any` |# Acknowledgements
Special thanks to the creators and maintainers of the following projects that made this tool possible:- [`astexplorer`](https://astexplorer.net/)
- [`babel`](https://babeljs.io/)
- [`babel-handbook`](https://github.com/jamiebuilds/babel-handbook)
- [`babel-plugin-tester`](https://github.com/babel-utils/babel-plugin-tester)
- [`flow-cheatsheet`](https://github.com/saltycrane/flow-cheatsheet)
- [`flow-typed`](https://github.com/flow-typed/flow-typed)
- [`recast`](https://github.com/benjamn/recast)
- [`typescript-vs-flowtype`](https://github.com/niieani/typescript-vs-flowtype)
- [`yargs`](https://yargs.js.org/)