Adds static typing to JavaScript to improve developer productivity and code quality.
OCaml JavaScript C Shell Ruby CSS Other
Latest commit fa2cd4d Jan 17, 2017 @gabelevi gabelevi committed with facebook-github-bot [RFC] Fix merge_type for FunT
Summary:
`merge_type` tries to take two types and merge them into a single
type. If the types can't be merged, it turns them into a union.

The "merge two FunT" case was a little weird. If they have different
parameters, we were just dropping all the parameters. It's probably more honest
to instead just create a union.

That said, I'm not 100% sure what this function is used for. Despite living in
flow_js.ml, it seems exclusively used by autocomplete. Maybe for autocomplete
returning a bad `FunT` is better than returning a good `UnionT`.

Reviewed By: samwgoldman

Differential Revision: D4375418

fbshipit-source-id: 19013ba2a089e63e742f6627ffc53a889b08f1be
Permalink
Failed to load latest commit information.
examples [flow docs] Main page, "Getting Started", & "Five Simple Examples" re… Mar 5, 2016
flow-typed ./tool test --watch Jul 22, 2016
hack [hack] Process read EOF might never arrive when child forks a daemon Jan 13, 2017
js Add emoji to server status messages Jan 11, 2017
lib $ReadOnlyArray<+T> - a supertype for all tuples and arrays Jan 11, 2017
newtests Constant folding array literal rest elements Jan 16, 2017
npm-flow-lib `flow-lib`: JS interfaces for Flow APIs Aug 9, 2016
resources [travis] use node6 when deploying Nov 14, 2016
scripts Gracefully handle no git or hg on Windows Jul 25, 2016
src [RFC] Fix merge_type for FunT Jan 17, 2017
tests fix returning complex types from constructors Jan 13, 2017
tsrc Avoid 80char lint errors in tool tests & fix flow check Jan 12, 2017
website $ReadOnlyArray<+T> - a supertype for all tuples and arrays Jan 11, 2017
.flowconfig Add npm-flow-lib to .flowconfig's ignore Sep 2, 2016
.gitattributes Ignore line endings in some esprima tests Oct 19, 2016
.gitignore [parser] add script to test flow against esprima3 tests Oct 18, 2016
.merlin Adds merlin file configuration Aug 23, 2015
.travis.yml stop building ocaml-4.01 on travis Dec 15, 2016
00_config.ocp Update build system and some fixes on the test-suite on Windows Dec 17, 2015
CONTRIBUTING.md Add contributing rules Apr 24, 2015
Changelog.md v0.37.4 Dec 20, 2016
LICENSE Updated all copyright license headers Feb 8, 2016
Makefile Fix Makefile not to spew on missing js_of_ocaml Dec 7, 2016
PATENTS Sync changes to upstream Apr 16, 2015
README.md Document the existence of compiled-to-JS Flow parser on npm Nov 1, 2016
README.win32 Update build system and some fixes on the test-suite on Windows Dec 17, 2015
_tags Fix parser makefile for 4.03.0 May 10, 2016
appveyor.yml Attempt to fix AppVeyor GitHub release artifact upload Nov 28, 2016
make.bat Continuous integration for Windows with AppVeyor Jun 24, 2016
ocp_build_flow.ocp.fb Fix the ocp-build build Nov 15, 2016
ocp_build_hack.ocp.fb Fix open source builds after sqlite work Nov 1, 2016
package.json Upgrade ./tool test's diff algo to support large strings Jan 6, 2017
runtests.sh Avoid runtests.sh log spew Jan 16, 2017
tool ./tool babel Sep 1, 2016

README.md

Flow Build Status Windows Build Status

Flow is a static typechecker for JavaScript. To find out more about Flow, check out flowtype.org.

For a background on the project, please read our launch blog post.

Requirements

Flow works with:

  • Mac OS X
  • Linux (64-bit)
  • Windows (64-bit)

There are binary distributions for each of these platforms and you can also build it from source on any of them as well.

Installing Flow

Flow is simple to install: all you need is the flow binary on your PATH and you're good to go.

Installing Flow Per Project

The recommended way to install Flow is via the flow-bin npm package. Adding flow-bin to your project's package.json:

  • provides a smoother upgrade experience, since the correct version of Flow is automatically used based on the revision you check out
  • installs Flow as part of your existing npm install workflow
  • lets you use different versions of Flow on different projects
npm install --save-dev flow-bin
node_modules/.bin/flow

Installing Flow Globally

Although not recommended, you can also install Flow globally (for example, perhaps you don't use npm or package.json).

The best way to install globally is via flow-bin:

npm install -g flow-bin
flow # make sure `npm bin -g` is on your path

On Mac OS X, you can install Flow via the Homebrew package manager:

brew update
brew install flow

You can also build and install Flow via the OCaml OPAM package manager. Since Flow has some non-OCaml dependencies, you need to use the depext package like so:

opam install depext
opam depext --install flowtype

If you don't have a new enough version of OCaml to compile Flow, you can also use OPAM to bootstrap a modern version. Install OPAM via the binary packages for your operating system and run:

opam init --comp=4.03.0
opam install flowtype
eval `opam config env`
flow --help

Getting started

Getting started with flow is super easy.

  • Initialize Flow by running the following command in the root of your project
flow init
  • Add the following to the top of all the files you want to typecheck
/* @flow */
  • Run and see the magic happen
flow check

More thorough documentation and many examples can be found at http://flowtype.org.

Building Flow

Flow is written in OCaml (OCaml 4.01.0 or higher is required) and (on Linux) requires libelf. You can install OCaml on Mac OS X and Linux by following the instructions at ocaml.org.

For example, on Ubuntu 14.04 and similar systems:

sudo apt-get install ocaml libelf-dev

On OS X, using the brew package manager:

brew install ocaml ocamlbuild libelf opam

Once you have these dependencies, building Flow just requires running

make

This produces a bin folder containing the flow binary.

Note: at this time, the OCaml dependency prevents us from adding Flow to npm. Try flow-bin if you need a npm binary wrapper.

Flow can also compile its parser to JavaScript. Read how here.

Using Flow's parser from JavaScript

While Flow is written in OCaml, its parser is available as a compiled-to-JavaScript module published to npm, named flow-parser. Most end users of Flow will not need to use this parser directly (and should install flow-bin from npm above), but JavaScript packages which make use of parsing Flow-typed JavaScript can use this to generate Flow's syntax tree with annotated types attached.

Running the tests

To run the tests, first compile flow using make. Then run bash ./runtests.sh bin/flow

There is a make test target that compiles and runs tests.

To run a subset of the tests you can pass a second argument to the runtests.sh file.

For example: bash runtests.sh bin/flow class | grep -v 'SKIP'

Join the Flow community

License

Flow is BSD-licensed. We also provide an additional patent grant.