Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bcherny/flow-to-typescript
Convert Flow-annotated files to TypeScript
https://github.com/bcherny/flow-to-typescript
compiler flow flowtype javascript typescript
Last synced: 6 days ago
JSON representation
Convert Flow-annotated files to TypeScript
- Host: GitHub
- URL: https://github.com/bcherny/flow-to-typescript
- Owner: bcherny
- License: mit
- Created: 2017-11-29T07:56:14.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2022-12-06T19:59:19.000Z (almost 2 years ago)
- Last Synced: 2024-10-18T11:26:28.120Z (18 days ago)
- Topics: compiler, flow, flowtype, javascript, typescript
- Language: TypeScript
- Size: 497 KB
- Stars: 430
- Watchers: 15
- Forks: 43
- Open Issues: 19
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Flow-to-TypeScript [![Build Status][build]](https://circleci.com/gh/bcherny/flow-to-typescript) [![npm]](https://www.npmjs.com/package/flow-to-typescript) [![mit]](https://opensource.org/licenses/MIT)
[build]: https://img.shields.io/circleci/project/bcherny/flow-to-typescript.svg?branch=master&style=flat-square
[npm]: https://img.shields.io/npm/v/flow-to-typescript.svg?style=flat-square
[mit]: https://img.shields.io/npm/l/flow-to-typescript.svg?style=flat-square> Compile Flow files to TypeScript
**In Pre-Alpha - contributions welcome.**
## Installation
```sh
# Using Yarn:
yarn add flow-to-typescript# Or, using NPM:
npm install flow-to-typescript --save
```## Usage
### CLI
```sh
# Install globally
yarn global add flow-to-typescript# Compile a file (all of these are equivalent)
flow2ts my/file.js.flow
flow2ts my/file.js.flow my/file.ts
flow2ts my/file.js.flow > my/file.ts
flow2ts -i my/file.js.flow -o my/file.ts
flow2ts --input my/file.js.flow --output my/file.ts
```### Programmatic
```js
import { compile } from 'flow-to-typescript'
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)
)
```## TypeScript vs. Flow
### Features
| Done? | | Flow | TypeScript |
|-------|-------------|-----------------------------------------|------------|
| ✅ | Maybe | `?type` (NullableTypeAnnotation) | `type \| null \| undefined` |
| ✅ | Null | `null` | `null` |
| ✅ | Undefined | `typeof undefined` | `undefined` |
| ✅ | Mixed | `mixed` | `unknown` |
| ✅ | Void | `void` | `void` |
| ✅ | Functions | `(A, B) => C` | `(a: A, b: B) => C` |
| ⚔ | Predicates (0) | `(a: A, b: B) => %checks` | `(a: A, b: B) => C` |
| ⚔ | Predicates (1) | `(a: A, b: B) => C %checks` | `(a: A, b: B) => C` |
| ✅ | Exact types | `{\| a: A \|}` | `{ a: A }` |
| ✅ | Indexers | `{ [A]: B }` | `{ [a: A]: B }` |
| ✅ | Opaque types | `opaque type A = B` | `type A = B` (not expressible) |
| ✅ | Variance | `interface A { +b: B, -c: C }` | `interface A { readonly b: B, c: C }` |
| ✅ | Bounds | `` | `` |
| ✅ | Casting | `(a: A)` | `(a as A)` |
| ✅ | Import default type | `import type A from './b'` | `import A from './b'` |
| ✅ | Import named type | `import type { A } from './b'` | `import { A } from './b'` |### Utilities
| Done? | | Flow | TypeScript |
|-------|-------------|-----------------------------------------|------------|
| | Keys | `$Keys` | `keyof A` |
| | Values | `$Values` | `A[keyof A]` |
| ✅ | ReadOnly | `$ReadOnly` | `Readonly` |
| ✅ | Exact | `$Exact` | `A` |
| | Difference | `$Diff` | TODO` |
| | Rest | `$Rest` | `Exclude` |
| | Property type | `$PropertyType` | `T[k]` |
| | Element type | `$ElementType` | `T[k]` |
| | Dependent type | `$ObjMap` | TODO |
| | Mapped tuple | `$TupleMap` | TODO |
| | Return type | `$Call` | `ReturnType` |
| | Class | `Class` | `typeof A` |
| | Supertype | `$Supertype` | `any` (warn - vote for https://github.com/Microsoft/TypeScript/issues/14520) |
| | Subtype | `$Subtype` | `B extends A` |
| | Existential type | `*` | `any` (warn - vote for https://github.com/Microsoft/TypeScript/issues/14466) |✅ Done
⚔ Babylon doesn't support it (yet)