Function Types
Function Types
Functions have two places where types are applied: Parameters (input) and the return value (output).
// @flow function concat(a: string, b: string): string { return a + b; } concat("foo", "bar"); // Works! // $ExpectError concat(true, false); // Error!
Using inference, these types are often optional:
// @flow function concat(a, b) { return a + b; } concat("foo", "bar"); // Works! // $ExpectError concat(true, false); // Error!
Sometimes Flow’s inference will create types that are more permissive than you want them to be.
// @flow function concat(a, b) { return a + b; } concat("foo", "bar"); // Works! concat(1, 2); // Works!
For that reason (and others), it’s useful to write types for important functions.
Syntax of functions
There are three forms