GenType doesn't retain the hierarchy for inner modules - how can I recreate it?

When I use @genType in an inner module, it doesn’t recreate the module hierarchy like in .bs.js files, instead it prefixes every let binding with the module name + underscore (e.g. “moduleName_bindingName”).

This behaviour is suboptimal for me since I want to be able to import the .gen exports in JS environments as a single nested (by module) JS object just like I could with the .bs.js files. Is there a particular reason why GenType doesn’t do that or is there an option I am missing?

As a workaround, I can of course recreate the object like this:

open InnerModule
@genType
let innerModule = {
  "innerBinding": innerBinding
  ...
}

This works fine, but it requires me to write the type of this object in the .resi file as well and there is a lot of code duplication for the binding types involved which I’d like to avoid.

Does anyone know a better solution?

Side note: For some reason, using @genType.opaque on types lets GenType generate an export with just the module name that binds to the module object from the .bs.js file, but this is not helping since it ignores the genType converters.

1 Like