Giter VIP home page Giter VIP logo

flow-to-typescript's Introduction

Flow-to-TypeScript Build Status npm mit

Compile Flow files to TypeScript

In Pre-Alpha - contributions welcome.

Installation

# Using Yarn:
yarn add flow-to-typescript

# Or, using NPM:
npm install flow-to-typescript --save

Usage

CLI

# 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

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 <A: string> <A extends string>
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<A> keyof A
Values $Values<A> A[keyof A]
ReadOnly $ReadOnly<A> Readonly<A>
Exact $Exact<A> A
Difference $Diff<A, B> TODO`
Rest $Rest<A, B> Exclude
Property type $PropertyType<T, k> T[k]
Element type $ElementType<T, K> T[k]
Dependent type $ObjMap<T, F> TODO
Mapped tuple $TupleMap<T, F> TODO
Return type $Call<F> ReturnType
Class Class<A> typeof A
Supertype $Supertype<A> any (warn - vote for microsoft/TypeScript#14520)
Subtype $Subtype<A> B extends A
Existential type * any (warn - vote for microsoft/TypeScript#14466)

✅ Done

⚔ Babylon doesn't support it (yet)

flow-to-typescript's People

Contributors

alexanderchan avatar bcherny avatar benjie avatar lgarron avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

flow-to-typescript's Issues

Empty package in npm

Hey! I believe it's error, that last version in npm just have one file in it with package.json.

ObjMap

type ObjMap<O extends {}, T> = { [K in keyof O]: T };

works in TS 3.1 (probably in 2.9 too)

Update: this is not the same as original $ObjMap, I thought about different use case

Npm Package Empty

Downloading the 1.0.0 package brought in a tar with only a package.json. A normally install npm install -D flow-to-typscript does not bring in any of the code.

╰─ [INSERT]  ➤  npm view flow-to-typescript dist.tarball
https://registry.npmjs.org/flow-to-typescript/-/flow-to-typescript-1.0.0.tgz

Maybe another publish will solve the issue

Continued development / support

This tool looks to be extremely useful and I was wondering if you personally intend to work on this further? Although I know nothing about how it works, I would certainly be open to contributing supposing PRs would be merged etc. I see great use for this tool in bridging the Flow/TS world 😃

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.