Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flow declaration files - getting started

Tags:

flowtype

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?

like image 634
Mark Volkmann Avatar asked Oct 16 '25 07:10

Mark Volkmann


1 Answers

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.

like image 107
Andy Avatar answered Oct 19 '25 12:10

Andy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!