Getting Started

Introduction to type checking with Flow

Flow is a static type checker for your JavaScript code. It does a lot of work to make you more productive. Making you code faster, smarter, more confidently, and to a bigger scale.

Flow checks your code for errors through static type annotations. These types allow you to tell Flow how you want your code to work, and Flow will make sure it does work that way.

1
2
3
4
5
6
// @flow
function square(n: number): number {
  return n * n;
}

square("2"); // Error!
string This type is incompatible with the expected param type of number

Because Flow understands JavaScript so well, it doesn’t need many of these types. You should only ever have to do a minimal amount of work to describe your code to Flow and it will infer the rest. A lot of the time, Flow can understand your code without any types at all.

1
2
3
4
5
6
// @flow
function square(n) {
  return n * n; // Error!
}

square("2");
string The operand of an arithmetic operation must be a number. string The operand of an arithmetic operation must be a number.

You can also adopt Flow incrementally and easily remove it at anytime, so you can try Flow out on any codebase and see how you like it.