noncom
November 23, 2025, 11:57pm
1
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
dsiu
November 24, 2025, 4:32am
2
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
noncom
November 24, 2025, 10:23pm
3
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
dsiu
November 25, 2025, 5:10am
4
I have added the docs, unit tests, and examples to my repo. Steal whatever you need from there.
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