Converts Flow declarations to TypeScript.
It is focused to work with code specially written for Flowest, not some random Flow code.
You can install js_of_ocaml version via npm:
$ npm install -D flowest
# Or: $ npm install --global flowest
Flowest can also be compiled to native code.
You can manually build it from the source code (it should work much faster).
$ flowest <input-file> <output-file>
# Or: $ npx flowest <input-file> <output-file>
It supports raw TypeScript via /*$$ ... */
:
type A = string
/*$$
type B = Partial<{ a: A, b: number }>
*/
/*::
type C = 3
*/
Output:
type A = string
type B = Partial<{ a: A, b: number }>
type C = 3
flowest-remove-next-line
and flowest-remove-line
:
/*$$ export type Id = unknown */
// flowest-remove-next-line
export opaque type Id = string
Output:
export type Id = unknown
- ✅ - Done
- 🚩 - Not fully correct
Status | Name | Flow | TypeScript |
---|---|---|---|
✅ | Maybe | ?T |
T | null | undefined |
✅ | Null | null |
null |
✅ | Mixed | mixed |
unknown |
✅ | Void | void |
void 🚩 |
BigInt | type A = 2n |
type A = 2n |
|
✅ | Union | A | B | C |
A | B | C |
✅ | Intersection | A & B & C |
A & B & C |
✅ | Typeof | typeof T |
typeof T |
✅ | Tuples | [T, U] |
[T, U] |
✅ | Functions | (A, B) => C |
(a: A, b: B) => C |
✅ | Predicates | (A, B) => C %checks |
(a: A, b: B) => C 🚩 |
✅ | Inexact types | { a: A, ... } or { a: A } |
{ a: A } 🚩 |
✅ | Exact types | {| a: A |} |
{ a: A } 🚩 |
✅ | Existential types | * |
any (not expressible) 🚩 |
✅ | Indexers | { [K]: T } |
{ [key: K]: T } |
✅ | Bounds | <T: string> |
<T extends string> |
✅ | Read-only fields | interface A { +b: B } |
interface A { readonly b: B } |
✅ | Write-only fields | interface A { -c: C } |
interface A { c: C } 🚩 |
Inline interfaces | type T = interface { a: A } |
- | |
Spread properties | { a: A, ...O } |
{ a: A } & O 🚩 |
|
Internal slots | { [[call]]: T => U } |
- | |
✅ | Partial | $Rest<T, {}> |
Partial<T> |
$Shape | $Shape<T> |
- (not expressible) | |
✅ | $ReadOnly | $ReadOnly<T> |
Readonly<T> |
✅ | $Keys | $Keys<T> |
keyof T |
✅ | $Values | $Values<T> |
T[keyof T] |
✅ | $Exact | $Exact<T> |
T 🚩 |
✅ | Class | Class<T> |
typeof T |
✅ | Property type | $PropertyType<O, k> |
O[k] |
✅ | Element type | $ElementType<T, K> |
T[K] |
✅ | Return type | $Call<F> |
ReturnType<F> |
$Call | $Call<F, A1, A2, ..., Ak> |
- (not expressible) | |
$Diff | $Diff<T, U> |
Pick<T, Exclude<keyof T, keyof U>> 🚩 |
|
$Rest | $Rest<T, U> |
- | |
$ObjMap | $ObjMap<T, <X>(X) => X> |
{ [P in keyof T]: T[P] } |
|
$ObjMapi | $ObjMapi<T, <I>(I) => I> |
{ [I in keyof T]: I } |
|
$TupleMap | $TupleMap<T, <X>(X) => X> |
{ [P in keyof T]: T[P] } |
|
✅ | $NonMaybeType | $NonMaybeType<T> |
NonNullable<T> 🚩 |
$CharSet | $CharSet<"abc"> |
- (not expressible) | |
$Trusted | $Trusted<T> |
- (not expressible) | |
$Private | $Private<T> |
- (not expressible) |
Status | Name | Flow | TypeScript |
---|---|---|---|
✅ | Import default type | import type T from './b' |
import T from './b' |
✅ | Import named type | import type { T } from './b' |
import { T } from './b' |
✅ | Export type | export type { T } |
export { T } |
✅ | Declare export | declare export class Cl {} |
export declare class Cl {} |
Declare export default | declare export default string |
- | |
Declare module | declare module 'm' { } |
- | |
Declare module exports | declare module.exports: T |
- | |
✅ | Type alias | type T = string |
type T = string |
✅ | Declare type alias | declare type T = string |
declare type T = string |
✅ | Interface | interface I extends A, B {} |
interface I extends A, B {} |
✅ | Declare interface | declare interface I {} |
declare interface I {} |
Opaque type | opaque type T = string |
- | |
Declare opaque type | declare opaque type T = string |
- | |
✅ | Declare variable | declare var a: number |
declare var a: number |
✅ | Declare function | declare function f(string): number |
declare function f(a: string): number |
✅ | Declare class | declare class B<T, U = D> extends A implements I1, I2 {} |
the same |
mixins in declare class |
declare class B mixins A {} |
- |
Status | Name | Flow | TypeScript |
---|---|---|---|
✅ | $ReadOnlyArray | $ReadOnlyArray<T> |
ReadonlyArray<T> |
✅ | $ReadOnlyMap | $ReadOnlyMap<K, V> |
ReadonlyMap<K, V> |
✅ | $ReadOnlySet | $ReadOnlySet<T> |
ReadonlySet<T> |
Iterator | - | - | |
Iterable | - | - | |
AsyncInterator | - | - | |
AsyncInterable | - | - | |
Generator | - | - | |
AsyncGenerator | - | - |
You can manually write TS code inside /*$$ ... */
for a feature that is not supported.
Supported version of Flow parser: 0.96.1