Q: Just so we're clear, ALL declaration of imported JS modules must be manually added?

Here are some scenarios, I’m pretty sure we’re in none of them. I don’t know how plausible any of them are:

  • You can imagine some fantasy version of Rescript that looks at .d.ts files and uses them to power interop. I realize there is not a 1:1 mapping from TS types to Rescript types.

  • You can also imagine some fantasy world where maybe there’s some codegen that does a pretty good job of making a Rescript declaration from a TS declaration, and then I can touch that up.

  • Or you can imagine a hell world where maybe a lot of the time it’s just not possible to bind a JS module to Rescript types properly.

I’ve studied the documentation on JS Interop starting here quite a bit but still don’t feel clear.

In general when it comes to TS interop, the sense I get is that there’s some codegen stuff people made for generating types, and that stuff is natively supported as of BS 5. But even the documentation on gentype is out-of-the-way and in some places just plain wrong (keeps referring to me needing to compile gentype or something, when I don’t).

It’s not clear to me if I should expect anything similar for the other direction of Rescript <> TS interop, and whether that’s a priority, or what. It’s not clear to me if we’ve made great progress on a Rescript version of DefinitelyTyped.

To me declarations feel like a big constraint on interop right now. Even having PropTypes integration would be nice.

This post is getting a little rambly. To summarize:

  • What is the state of inference or declaration codegen when binding to JS modules?
  • What should I expect in the future? What are the priorities and technical possibilities?
  • What is the state of easy-to-install bindings/declarations for popular JS modules?

As a newcomer to ReScript I’m just listening in here :blush:

Some form of codegen based on the existing work in definitelytyped could, possibly ,make it easier for people to start transitioning to ReScript? But I’m also unsure as to what’s already been tried / exists

There’s some very promising progress in this project: https://github.com/tmattio/js-bindings

Currently it does not have a back-end to emit code in ReScript syntax targeting the ReScript ecosystem instead of js_of_ocaml. But I’ve been told it should not be difficult to add.

1 Like

That does indeed look very promising, thanks for the link