Skip to content

M. Type Checking our code

Cody Brunner edited this page Mar 13, 2017 · 3 revisions

This being a named function that just returns a string we can run type-checking with flow as follows:

/* @flow */
const rcjh = (): string => 'ROCK CHALK JAYHAWK, KU!';

export default rcjh;

What we have declared in our code is that the function rcjh() should return a string as its value.

If we were to add a function with parameters we could type-check our arguments as well:

/* @flow */
const sum = (a: number, b: number): number => a + b;
sum('one', '2'); // Flow-Error: type not compatible with expected param type: number