A static type checker for JavaScript

Type Inference#

Flow uses type inference to find bugs even without type annotations. It precisely tracks the types of variables as they flow through your program.

Idiomatic JS#

Flow is designed for JavaScript programmers. It understands common JavaScript idioms and very dynamic code.

Realtime Feedback#

Flow incrementally rechecks your changes as you work, preserving the fast feedback cycle of developing plain JavaScript.

Flow can catch common bugs in JavaScript programs before they run, including:

  • silent type conversions,
  • null dereferences,
  • and the dreaded undefined is not a function.
1
2
3
4
5
// @flow
function foo(x) {
  return x * 10;
}
foo('Hello, world!');
show Flow output hide Flow output
$> flow
3:   return x * 10;
            ^ string. The operand of an arithmetic operation must be a number.

Flow also lets you gradually add type assertions to your code:

1
2
3
4
5
// @flow
function bar(x): string {
  return x.length;
}
bar('Hello, world!');
show Flow output hide Flow output
$> flow
3:   return x.length;
            ^^^^^^^^ number. This type is incompatible with the expected return type of
2: function bar(x): string {
                    ^^^^^^ string

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