Wrong functions clojure js output that couses runtime error

I have a function that returns another function. At first I’ve written it like this:

type baz = {foo: option<bool>}
type bar = unit => baz
let make = (): bar => {
  () => {
    {
      foo: None,
    }
  }
}

The make function has a type unit => bar which is correct.
After this I had to spend a bunch of time (partially because I haven’t written tests for this part) trying to figure out why the Curry helper didn’t work properly in js output before I’ve noticed that the module’ve been transpiled into this:

function make(param, param$1) {
  return {
          foo: undefined
        };
}

export {
  make ,
  
}

Just a function that imediatly returns a result.
I’ve rewritten my module to this, that helped with the problem, but still it wasn’t a good experience debugging the error.

type baz = {foo: option<bool>}
type bar = unit => baz
let make = () => {
  let bar: bar = () => {
    {
      foo: None,
    }
  }
  bar
}

On the rescript side the make’s type in both cases was correct.

Is it possible you could leverage the “uncurry” syntax to make it work with an example closer to your original?

This works as expected. Only uncurried calling convention are guaranteed to keep the arity when compiling to JS. For curried function, the compiler has the freedom to do such optimizations

Here is a full example:

type baz = {foo: option<bool>}
type bar = (.unit) => baz

let make = (): bar => {
  (.) => {
    {
      foo: None,
    }
  }
}

which compiles to

function make(param) {
  return function () {
    return {
            foo: undefined
          };
  };
}

exports.make = make;

Playground Link