Gentype export to ts file instead of tsx

So, i was trying to use Rescript for a backend nodejs app that already uses typescript. I tried to use gentype to generate ts files, but looks like it is generating all the typed files only as tsx files.

Can you advise if i have to configure something to make gentype to generate ts file instead of tsx file?

In bsconfig.json do this

 "gentypeconfig" : {
   ... 
   "generatedFileExtension": ".gen.ts"
   ... 
} 

Agrees it should definitely be documented somewhere!

2 Likes

Thanks for the hint, added it to the updated GenType docs on our website: gentype: add generatedFileExtension docs · rescript-association/rescript-lang.org@4bf2e0f · GitHub

2 Likes

@tsnobip Thank you very much for a very prompt response. That helped a lot. One more question.

Can I define the generatedFileExtension per folder? For Components folder i want it to be tsx and for reducers I want it to be ts.

I guess you would need to have those in different projects, I don’t think you can configure this per folder.

1 Like

But how do you instruct rescript to generate ts files instead of js ones?

Seems that you don’t do that, instead you generate both.
In order for gentype to work you need to install it on your project:

yarn add gentype

And then add the following config to your bsconfig.json

  "gentypeconfig": {
    "language": "typescript",
    "generatedFileExtension": ".gen.ts"
  }

I have to say that I don’t like much the generated output. Specially because it is bringing some runtime dependencies that are 100% not needed (curry for a non curried function, for example)