Avoiding "param" in js output

I’m working on zero cost bindings for jest, and noticed that my test function adds a param to the JS output

external test: (string, () => unit) => unit = "test"
test("it xxx", ignore)

produces:

test("it xxx", (function (prim) {
  
      }));

Is there a better way to write the binding so that the prim doesn’t get added to the callback function? This parameter causes jest tests to hang on async tests as they expect done() to be called explicitly if there’s a parameter

1 Like

It is because of the curry in your unit => unit function. Try this with the uncurried function:

external test: (string, (. unit) => unit) => unit = "test"
test("it xxx", (. ()) => Js.log("yo"))

And here is the JS output.

test("it xxx", (function () {
        console.log("yo");
      }));

playground

Of course, you will have to pass uncurried functions in which may be a pain for you depending on how your code is going.

2 Likes

That should also be solveable with the @uncurry annotation.

1 Like

It is a good point.

Though, I always thought this warning from the old docs was a little off-putting:

In general, bs.uncurry is recommended; the compiler will do lots of optimizations to resolve the currying to uncurrying at compile time. However, there are some cases the compiler can’t optimize it. In these cases, it will be converted to a runtime check.

(emphasis added)

Though I don’t know it practice how often it gets converted to a runtime check, or if is even still applicable in current ReScript version.