Suppose I have this in a file named "math.js".
function double(n) {
return n * 2;
}
exports.double = double;
If I want to declare the parameter and return type of the "double" function in a separate file named "math.js.flow", what would I put in that file?
You would put this in your .js.flow
file:
// @flow
declare export function double(n: number): number;
Note that if your .js
module contains module.exports = function foo()
then you will need to do the following:
declare function foo(): void;
declare module.exports: typeof foo;
You can also generate .js.flow
files with the flow gen-flow-files
command. At the time of writing, it's buggy and sometimes fails, so I still write my .js.flow
files manually, but if it succeeds you can look at what it output to reverse engineer more aspects of the .js.flow
format.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With