Hi. As far as I understood, if you make reference to a function that is implemented in another file (module) you need to explicitly annotate the types for the function before calling Flow type checker. Like in this example:
/**
* Size.js
* @flow
*/
function size(input: string): number {
return input.length;
}
module.exports = size;
/**
* UseSize.js
* @flow
*/
var size = require('./Size');
var result = size('Hello Flow');
In this case, two files, we have to "manually" inform to Flow that 'function size' returns a 'number' and receives a 'string' as argument. Otherwise, it won't be able to infer the types and it will give a 'Missing annotation error' instead. Is this information correct? Do we really need to annotate the types manually in these cases?
Thank you in advance!
Yep, annotations are required at module boundaries. See https://flowtype.org/docs/type-annotations.html#module-boundaries
Also see: https://flowtype.org/docs/modules.html#missingrequired-annotations
This appears to have changed, as those links are now broken, but but there are still annotations which are required. Is there a new reference describing where annotations are required? I can't find it anywhere in the docs.
Most helpful comment
This appears to have changed, as those links are now broken, but but there are still annotations which are required. Is there a new reference describing where annotations are required? I can't find it anywhere in the docs.