A static type checker for JavaScript

Quick Reference Download

What is Flow?

Flow is a static type checker, designed to quickly find errors in JavaScript applications:

1
2
3
4
5
// @flow
function foo(x) {
  return x * 10;
}
foo('Hello, world!');
$> flow
  3:   return x * 10;
              ^ string. This type is incompatible with
  3:   return x * 10;
              ^^^^^^ number

Flow also lets you gradually opt-in to statically type checking your code:

1
2
3
4
5
// @flow
function bar(x: string, y: number): string {
  return x.length * y;
}
bar('Hello', 42);
$> flow
  3:   return x.length * y;
              ^^^^^^^^^^^^ number. This type is incompatible with
  2: function bar(x: string, y: number): string {
                                         ^^^^^^ string

Typed JavaScript code with Flow annotations easily transforms down to regular JavaScript, so it runs anywhere.

Why Flow?

The goal of Flow is to find errors in JavaScript code with little programmer effort. Flow relies heavily on type inference to find type errors even when the program has not been annotated - it precisely tracks the types of variables as they flow through the program.

At the same time, Flow is a gradual type system. Any parts of your program that are dynamic in nature can easily bypass the type checker, so you can mix statically typed code with dynamic code.

Flow also supports a highly expressive type language. Flow types can express much more fine-grained distinctions than traditional type systems. For example, Flow helps you catch errors involving null, unlike most type systems.

We first introduced Flow at the @Scale Conference in September:

Using Flow

Start out with our Getting Started guide and try Flow for yourself.

Flow is open-source and still evolving. It is used heavily within Facebook and we will continue to develop it in the open. We hope it will be useful for other JavaScript projects, so please try it out, join the community, and give us feedback!