I have a function, that returns another function, say
let registerSW = (opts) => () => ()
the return type of the registerWS
is a function to update service worker, let’s call it updateSW
. In the opts
I’m passing a React Element, that renders a button, which calls the updateSW
on click.
let updateSW = registerSW({ foo: <button onClick={_ => updateSW() }/> })
So the function is kind of recursive but it refers to itself in a function argument, not in it’s body, and it does that via another callback - the onClick
handler. Something perfectly valid in JS is invalid in Rescript. The rec
keyword does not help for there is no function declaration, but function invocation. The function is external, co I cannot declare it as rec
because again, bindings are not function declaration. And because I refer to the return type in function argument, it is not a recursion in a classic sense. I’m currently using %raw
to escape the error, but I am curious if there is a way to write this in a valid Rescript?