javascriptflowtypeflow-typed

How to declare flow type for named exports?


I have a file with a default export and some other named exports.

  module.exports = function1;
  exports.names= [];
  exports.getStrings = getStrings;

function1 and getString functions are defined.

Now, in the .flow file i want to declare the types of these variables.

declare module.function1: (param: ?(string | number)) => null | number;
declare exports.names: $ReadOnlyArray<string>;
declare exports.getStrings: () => {[string]: string};

This is giving flow parse error. I have referred to the flow documentation but couldn’t find anything.


Solution

  • This should work:

    declare export default {
      (param: ?(string | number)): null | number,
      names: $ReadOnlyArray<string>,
      getStrings: () => {[string]: string},
    };