0.0.6 • Published 5 years ago

@esmbly/transformer-flow v0.0.6

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

@esmbly/transformer-flow

Transform Flow files to TypeScript.

Installation

# Using Yarn:
yarn add @esmbly/transformer-flow

# Or, using NPM:
npm install @esmbly/transformer-flow --save

Getting Started

Check out Using the Flow transformer guide for a step-by-step guide on how to get started with @esmbly/transformer-flow and the command-line interface.

Try

Try it out in the Esmbly version of WebAssembly Studio!

Usage

The @esmbly/transformer-flow transforms Flow files to TypeScript. In order to use it, make sure you have @esmbly/cli installed .

The following Esmbly configuration will transform all JavaScript files located in the src directory and output TypeScript files to the dist directory.

// esmbly.config.js

const Flow = require('@esmbly/transformer-flow');

module.exports = {
  input: ['./src/**/*.js'],
  transformers: [
    Flow.createTransformer(),
  ],
  output: [
    {
      format: '.ts',
      outDir: 'dist',
      rootDir: 'src',
    },
  ],
};

Configuration

The createTransformer() method accepts an optional configuration object (see the FlowTransformerOptions interface). The following options are possible.

OptionDescriptionTypeDefault
removeFlowFlags (optional)Whether or not to remove any // @flow commentsbooleantrue
customRules (optional)An object containing any custom rules which should be applied (existing rules can be overridden). Check out the custom-rule example for further details.CustomRules

Examples

Status

Supported?FlowTypeScript
Primitive Typesboolean \| number \| string \| null \| undefinedboolean \| number \| string \| null \| undefined
Voidvoidundefined
Literal Typestype Two = 2;type Two = 2;
Mixed Typesmixedunknown
Any Typesanyany
Maybe Types?typetype \| null \| undefined
Function Types(str: string) => boolean(str: string) => boolean
Function Shorthand(A, B) => C(a: A, b: B) => C
Predicate Functions(a: A, b: B) => C %checks(a: A, b: B) => C
Object Types{ foo: boolean }{ foo: boolean }
Exact object types{\| a: A \|}{ a: A }
Indexers{ [A]: B }{ [a: A]: B }
Array TypesArray<string>, string[]Array<string>, string[]
Tuple Typestype A = [number, boolean]type A = [number, boolean]
Class Types
Opaque typesopaque type A = Btype A = B (not expressible)
Interface Types
Varianceinterface A { +b: B, -c: C }interface A { readonly b: B, c: C }
Generic Types
Bounds<A: string><A extends string>
Union Typesnumber \| booleannumber \| boolean
Disjoint unions
Intersection TypesA & BA & B
Typeof types
Typeof undefinedtypeof undefinedundefined
Type Casting(a: A)(a as A)
Import default typeimport type A from './b'import A from './b'
Import named typeimport type { A } from './b'import { A } from './b'

Utilities

Done?FlowTypeScript
Keys$Keys<A>keyof A
Values$Values<A>A[keyof A]
ReadOnly$ReadOnly<A>Readonly<A>
ReadOnlyArray$ReadOnlyArray<A>ReadonlyArray<A>
Exact$Exact<A>A
Difference$Diff<A, B>?
Rest$Rest<A, B>?
Property type$PropertyType<T, k>T[k]
Element type$ElementType<T, K>T[k]
Element type$NonMaybeType<T>NonNullable<T> (strictNullChecks)
ObjMap$ObjMap<T, F>?
ObjMapi$ObjMapi<T, F>?
TupleMap$TupleMap<T, F>?
Call$Call<F>ReturnType
ClassClass<A>typeof A
ShapeShape<T>Partial<T>
Supertype$Supertype<A>any (deprecated)
Subtype$Subtype<A>B extends A (deprecated)
Existential type*any (deprecated)

✅ Done
❌ Not implemented yet
❓ Status not known

Contributing

All types of contributions are very much welcome. Check out our Contributing Guide for instructions on how to get started.

Credits

@esmbly/transformer-flow is a customization/extension of the flow-to-typescript project ( ❤️) which is released under the following MIT license.

Copyright 2017 Boris Cherny <boris@performancejs.com> 

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.