Docs / GenType / Getting Started

Getting Started

genType is tightly integrated in the ReScript Compiler. It only requires minimal setup.



bs-platform 8.3.0 or higher: use genType 3.36.0 or higher.

bs-platform 8.2.0 or higher: use genType 3.31.0 or higher.

bs-platform 8.1.1 or higher: use genType 3.27.0 or higher.

bs-platform 8.0.0 or higher: use genType 3.26.0 or higher.

For earlier versions, check the genType README requirements section.

Install the binaries via npm (or yarn):

npm install --save-dev gentype # Verify installed gentype binary npx gentype --help

Add a gentypeconfig section to your bsconfig.json (See Configuration for details):

"gentypeconfig": { "language": "untyped", "shims": {}, "debug": { "all": false, "basic": false } }

For running gentype with ReScript via npm workflow, add following script in your package.json:

scripts: { "build": "bsb -make-world", "clean": "bsb -clean-world" }

Note: bsb will automatically detect your installed genType version.


Every genType powered project requires a configuration item "gentypeconfig" at top level in the project's bsconfig.json. (The use of a separate file gentypeconfig.json is being deprecated). The configuration has following structure:

//... "gentypeconfig": { "language": "typescript" | "flow" | "untyped", "shims": { "ReasonReact": "ReactShim" } }
  • language

    • "typescript" : Generate *.gen.tsx files written in TypeScript.

    • "flow": Generate *.gen.js files with Flow type annotations.

    • "untyped": Generate *.gen.js files in vanilla JavaScript.

  • shims

    • e.g. Array<string> with format: "RescriptModule=JavaScriptModule"

    • Required to export certain basic ReScript data types to JS when one cannot modify the sources to add annotations (e.g. exporting ReScript lists)

Adding Shims (TS & Flow)

A shim is a TS / Flow file that provides user-defined definitions for library types.

Configure your shim files within "gentypeconfig" in your bsconfig.json, and add relevant .shims.js files in a directory which is visible by ReScript e.g. src/shims/. An example shim to export ReactEvent can be found here.

Testing the Whole Setup

Open any relevant *.res file and add @genType annotations to any bindings / values / functions to be used from JavaScript. If an annotated value uses a type, the type must be annotated too. See e.g. Hooks.res.

Save the file and rebuild the project via npm run bs:build or similar. You should now see a *.gen.tsx (for TypeScript, or *.gen.js for Flow) file with the same name (e.g. MyComponent.res -> MyComponent.gen.tsx).

Any values exported from MyComponent.res can then be imported from JS. For example:

import MyComponent from "./components/MyComponent.gen";


We prepared some examples to give you an idea on how to integrate genType in your own project. Check out the READMEs of the listed projects.

Please make sure to build genType before trying to build the examples.

Experimental features

These features are for experimentation only. They could be changed/removed any time, and not be considered breaking changes.

  • Export object and record types as interfaces. To activate, add "exportInterfaces": true to the configuration. The types are also renamed from name to Iname.

  • Emit prop types for the untyped back-end. To activate, add "propTypes": true and "language": "untyped" to the configuration.


  • in-source = true. Currently only supports ReScript projects with in-source generation and .bs.js file suffix.

  • Limited namespace support. Currently there's limited namespace support, and only namespace:true is possible, not e.g. namespace:"custom".


See for a complete list of features, fixes, and changes for each release.