Bindings to a JS library with method overloads

I’m wrapping a JS/TS library, and everything works fine until I need to wrap a method that has an optional second argument. It starts like this:

module Graphology = {
  type directedGraph = {
    addNode: (string) => string,
    addEdge: (string, string) => string,
  }

  @new @module("graphology")
  external createDirectedGraph: unit => directedGraph = "DirectedGraph"
}

and this works. However, addNode() has an overload with an extra argument like here. What would be the way to wrap that?

2 Likes

I have worked on my own Graphology bindings for ReScript a while ago and worked out most kinks like supporting node/edge attributes and many iteration methods, etc.

Have a look at my repo here GitHub - dsiu/rescript-graphology at rescript-v12 and see if it helps you write your own bindings.

It might be overkill for you since I used quite a bit of module module functions.

You can look at the Demo.res and Demo_AStar.res examples as starting points.

3 Likes

Wow, these bindings look like they would cover everything already!
Thank you very much, this is not only going to help directly, but also work as a learning example!

1 Like

I have added the docs, unit tests, and examples to my repo. Steal whatever you need from there. :wink:

It is still on rescript-v12 branch but I plan to merge it to main soon after ReScript 12 is released (should be pretty soon I think).

1 Like