Introducing @juspay/rescript-bindgen

We’ve open-sourced a tool that generates ReScript bindings directly from TypeScript definitions.

If you’ve ever wanted to use a TypeScript library in ReScript but found writing bindings manually tedious, this tool aims to automate much of that work.

Why we built it:

  • Reduce friction when adopting ReScript in existing TypeScript ecosystems
  • Speed up binding generation for large libraries
  • Make it easier for teams migrating from TypeScript to ReScript

We’re looking for feedback from the ReScript community on:

  • Generated API ergonomics
  • Edge cases and unsupported TypeScript features
  • Libraries you’d like us to test against

NPM: @juspay/rescript-bindgen

Feedback, issues, and contributions are welcome!

2 Likes

wow this looks awesome! I’ll try it! I’ll also take a look at the implementation. I’d be very interested in knowing more about the challenges you’ve faced and the bindings design decisions you’ve made.

Thanks! I’d love to hear your feedback after you’ve had a chance to try it.

The motivation came from one of our internal projects. We have a design system called blend-design-system, and we maintain ReScript bindings for it in blend-rescript.

We were writing the bindings manually, and whenever a new version of blend-design-system was released, we wouldn’t know if something had changed or been fixed unless we ran into an issue and later discovered that our bindings were outdated.

So I thought of building a tool that could generate the bindings for blend-rescript automatically. Since ReScript is used across Juspay, the idea was to have a package that the whole organization could use. Whenever a new version of blend-design-system is released, we can automate binding generation (for example through GitHub Actions), making it much easier for developers to keep the bindings up to date.

That was the original motivation behind the project.

This sounds awesome, but I can’t find @juspay/rescript-bindgen on the npm registry.

https://www.npmjs.com/package/@juspay/rescript-bindgen check this @JohnsongDetlev, the coverage is good for now around 80-90% for the packages we checked and we are still improving on it.

Ah, the readme has an error, that’s the issue.

I.e. npx rescript-bindgen --pkg @mui/material --out generated --report instead of npx @juspay/rescript-bindgen --pkg @mui/material --out generated --report

But is this just for react components? Or ts packages in general? I tried it out with hono, but it just says that all exports are not a react component:

pnx @juspay/rescript-bindgen --pkg hono --out generated --report
[resolve] installing hono into scratch cache…
[bindgen] entry: /Users/johannesspaceteams/Library/pnpm/store/v11/links/@juspay/rescript-bindgen/1.0.0/073a43a5955cb454d759479565ff8a62fc22afb557659327d3b2224713789c9c/node_modules/@juspay/rescript-bindgen/.bindgen-cache/node_modules/hono/dist/types/index.d.ts
[bindgen] @module("hono")
[bindgen] No React components found to generate.
[bindgen] skipped: Env(not-a-component), ErrorHandler(not-a-component), Handler(not-a-component), MiddlewareHandler(not-a-component), Next(not-a-component), NotFoundResponse(not-a-component), NotFoundHandler(not-a-component), ValidationTargets(not-a-component), Input(not-a-component), Schema(not-a-component), ToSchema(not-a-component), TypedResponse(not-a-component), Context(not-a-component), ContextVariableMap(not-a-component), ContextRenderer(not-a-component), ExecutionContext(not-a-component), HonoRequest(not-a-component), InferRequestType(not-a-component), InferResponseType(not-a-component), ClientRequestOptions(not-a-component)

Thanks for the feedback !!

Currently it’s just for react component, but yes the aim is to make it a ts package in general and we are working on the same.

1 Like