@new @module binding causing TypeError: is not a constructor

I am trying to write up a simple binding to Fuse.js (https://fusejs.io/)

Current Error:
TypeError: FuseJs is not a constructor

The generated code seems fine, so not totally sure why we are facing this error.

FuseJs.res

type options = {keys: array<string>}

type result = {item: Js.Json.t, refIndex: int}

type fuse = {search: string => result}

@new @module external make: (array<Js.Json.t>, options) => fuse = "fuse.js"

Thanks in advance!

Well it ends up I had to use the “default” method which was odd because the docs show commonJs without a default?

Working:

type options = {keys: array<string>}

type result = {item: Js.Json.t, refIndex: int}

type fuse = {search: (. string) => result}

@new @module("fuse.js") external make: (array<Js.Json.t>, options) => fuse = "default"
1 Like

Hello. I’ve cleaned up the import/export bindings page a little; hopefully this helps.

The idea is that you should first write the JS code you’d like to see ReScript to compile to, then try to nudge your bindings toward outputting that.

2 Likes