goodmind / flowest

Convert Flow declarations to TypeScript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Flowest

Converts Flow declarations to TypeScript.

It is focused to work with code specially written for Flowest, not some random Flow code.

Installation

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).

Usage

$ flowest <input-file> <output-file>
# Or: $ npx flowest <input-file> <output-file>

Features

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

Table

  • βœ… - 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)

Statements

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 {} -

Core libdefs

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

About

Convert Flow declarations to TypeScript

License:MIT License


Languages

Language:OCaml 98.1%Language:Makefile 1.0%Language:JavaScript 0.5%Language:Shell 0.4%