Facebook Open-Sources JavaScript Static-Type Checker Flow

The latest software to be open-sourced by Facebook is Flow, a static-type checker for JavaScript.

FlowLogo650The latest software to be open-sourced by Facebook is Flow, a static-type checker for JavaScript.

Extensive details about Flow are available in this post on the Facebook Engineering blog by software engineers Avik Chaudhuri, Basil Hosmer and Gabriel Levi, but here are the basics:

Flow adds static typing to JavaScript to improve developer productivity and code quality. In particular, static typing offers benefits like early error checking, which helps you avoid certain kinds of runtime failures, and code intelligence, which aids code maintenance, navigation, transformation and optimization.

We have designed Flow so developers can reap its benefits without losing the “feel” of coding in JavaScript. Flow adds minimal compile-time overhead, as it does all its work proactively in the background. And Flow does not force you to change how you code — it performs sophisticated program analysis to work with the idioms you already know and love.

Flow’s type-checking is opt-in — you do not need to type-check all your code at once. However, underlying the design of Flow is the assumption that most JavaScript code is implicitly statically typed; even though types may not appear anywhere in the code, they are in the developer’s mind as a way to reason about the correctness of the code. Flow infers those types automatically wherever possible, which means that it can find type errors without needing any changes to the code at all. On the other hand, some JavaScript code, especially frameworks, makes heavy use of reflection that is often hard to reason about statically. For such inherently dynamic code, type-checking would be too imprecise, so Flow provides a simple way to explicitly trust such code and move on. This design is validated by our huge JavaScript codebase at Facebook: Most of our code falls in the implicitly statically typed category, where developers can check their code for type errors without having to explicitly annotate that code with types.

Flow is implemented mostly in OCaml. The code base is under active development and will continue to rapidly evolve in the next few months. In addition to working on Facebook-scale code bases, we hope that the implementation of Flow’s analysis engine will be useful to those building similar development tools for JavaScript and other languages. Please let us know if you wish to collaborate!

david.cohen@adweek.com David Cohen is editor of Adweek's Social Pro Daily.