Search code examples
javascriptflowtypeflow-typed

What is the meaning of $Export variable in Flow's libdefs?


I’m using flow-typed.

I encountered the variable $Export in some of libdefs. I have no idea what it is and where it’s documented.

For me it seems similar to Utility Types, but the problem that $Export isn’t described there. Could any body explain it and where it comes from?

declare module "@material-ui/core/AppBar/AppBar" {
  import type {ComponentType, Node} from "react";

  declare type Color = "inherit" | "primary" | "secondary" | "default";
  declare type Position = "fixed" | "absolute" | "sticky" | "static" | "relative";

  declare module.exports: ComponentType<{
    children?: Node,
    className?: string,
    classes?: Object,
    color?: Color,
    position?: Position
  }>;
}

declare module "@material-ui/core/AppBar" {
  declare module.exports: $Exports<"@material-ui/core/AppBar/AppBar">;
}

Solution

  • Looking at this Github thread they seem to be internal methods

    The definition seems to be here:

    https://github.com/facebook/flow/blob/master/src/typing/type_annotation.ml#L491

    where there is this comment:

    (*  $Exports<'M'> is the type of the exports of module 'M'
    

    So it's basically a module loader for all intents and purposes until the item in the TODO list arrives

     (** TODO: use `import typeof` instead when that lands **)