Flow - static type analysis in JS from Facebook

    Flow is a static code analyzer and a set of syntax constructs for directly indicating the type of a variable.
    Flow can calculate the type of a variable without making changes to the code (unlike TypeScript), which allows you to start using it now in any project. It is also possible to independently specify types in the style of TypeScript.

    There are 3 modes:
    1. Do not check anything, by default
    2. Validation without using annotations (with comment annotation, as in React)
    3. Strict indication of the type of variable (with changes directly to the code)

    /* @flow */
    function foo(x) {
      return x * 10;
    foo('Hello, world!');

    $> flow
    hello.js:5:5,19: string
    This type is incompatible with
      hello.js:3:10,15: number

    In this case, the analyzer independently deduced the type of the variable, but you can also tell:

    /* @flow */
    function foo(x: string, y: number): string {
      return x.length * y;
    foo('Hello', 42);

    $> flow
    hello.js:3:10,21: number
    This type is incompatible with
      hello.js:2:37,42: string

    There is also a weak mode that allows you to check the code for errors that are easy to quickly fix:
    • Potentially possible values undefinedand nullthat are easy to fix by adding validation
    • Primitive errors with types, like true + 3

    Flow setting is written in OCaml (> = 4.01.0).
    There are binary assemblies for OSX and Linux , Windows is not supported.
    For those who write on OCaml, you can use the OPAM package manager:
    opam install flowtype

    And OSX users have the opportunity to deliver through Brew:
    brew install flow

    Future plans
    • Support for existing TypeScript interface files (.d.ts) with DefinitelyTyped.org in a similar format for Flow
    • Support for ES6 modules
    • Compiling Flow in JS with js_of_ocaml
    • Integration with code editors and IDEs
    • Error sorting and file filtering
    • Improve error messages: cause of error and its tracing
    • A bunch of features of typed systems such as bounded polymorphism, enumerations, purity analysis of functions, and more


    Also popular now: