Giter Club home page Giter Club logo

flowest's Introduction

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

flowest's People

Contributors

eilvelia avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

goodmind

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.