0.1.0 • Published 5 years ago

flowest v0.1.0

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

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:

/*$$ type D = Partial<{ a: A, b: number }> */
// flowest-remove-next-line
type D = $Shape<{ a: A, b: number }>

Output:

type D = Partial<{ a: A, b: number }>

Table

  • ✅ - Done
  • 🚩 - Not fully correct
StatusNameFlowTypeScript
Maybe?TT \| null \| undefined
Nullnullnull
Mixedmixedunknown
Voidvoidvoid 🚩
BigInttype A = 2ntype A = 2n
UnionA | B | CA | B | C
IntersectionA & B & CA & B & C
Typeoftypeof Ttypeof 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 fieldsinterface A { +b: B }interface A { readonly b: B }
Write-only fieldsinterface A { -c: C }interface A { c: C } 🚩
Inline interfacestype T = interface { a: A }-
Spread properties{ a: A, ...O }-
Internal slots{ [[call]]: T => U }-
Generator--
AsyncGenerator--
Partial$Rest<T, {}>Partial<T>
$Shape$Shape<T>- (not expressible)
$ReadOnly$ReadOnly<T>Readonly<T>
$ReadOnlyArray$ReadOnlyArray<T>ReadonlyArray<T>
$Keys$Keys<T>keyof T
$Values$Values<T>T[keyof T]
$Exact$Exact<T>T 🚩
ClassClass<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)
$Rest$Rest<O1, O2>-
$Diff$Diff<O1, O2>-
$ObjMap$ObjMap<{ a: A }, <X>(X) => X>-
$ObjMapi$ObjMapi<{ a: A }, <I>(I) => I>-
$TupleMap$TupleMap<[1, 2, 3], <X>(X) => X>-
$NonMaybeType$NonMaybeType<T>NonNullable<T> 🚩
$CharSet$CharSet<"abc">- (not expressible)
$Trusted$Trusted<T>- (not expressible)
$Private$Private<T>- (not expressible)

Statements

StatusNameFlowTypeScript
Import default typeimport type T from './b'import T from './b'
Import named typeimport type { T } from './b'import { T } from './b'
Export typeexport type { T }export { T }
Declare exportdeclare export class Cl {}export declare class Cl {}
Declare export defaultdeclare export default string-
Declare moduledeclare module 'm' { }-
Declare module exportsdeclare module.exports: T-
Type aliastype T = stringtype T = string
Declare type aliasdeclare type T = stringdeclare type T = string
Interfaceinterface I extends A, B {}interface I extends A, B {}
Declare interfacedeclare interface I {}declare interface I {}
Opaque typeopaque type T = string-
Declare opaque typedeclare opaque type T = string-
Declare variabledeclare var a: numberdeclare var a: number
Declare functiondeclare function f(string): numberdeclare function f(a: string): number
Declare classdeclare class B<T, U = D> extends A implements I1, I2 {}the same
mixins in declare classdeclare class B mixins A {}-

You can manually write TS code inside /*$$ ... */ for a feature that is not supported.


Supported version of Flow parser: 0.96.1