Is Js.Promise.then_ curried?

Hello there.

Trying to do some http async stuff I got really confused about why in the following code:

let url = ""

let data = Axios.get(url)->Js.Promise.then_(res => {

I get the following error:

  This has type:
    Js.Promise.t<Axios_types.response<'a, 'b>> (defined as
      Js_promise.t<Axios_types.response<'a, 'b>>)
  Somewhere wanted: 'c => Js.Promise.t<'d>

I get it, my callback wants a function with the type 'c => Js.Promise.t<'d>. What is really confusing is that I supposed that my callback should accept a promise as a parameter, and not a function. And I don’t exactly know why adding an underscore (as shown at the docs) solves the problem.
Why is it necessary? The old reasonml syntax didn’t need to include the underscore, so is this gonna change in the future?

Look at the type of Js.Promise.then_:

let then_: ('a => t<'b>, t<'a>) => t<'b>

The first parameter is the callback, the second parameter is the input promise.

When you do promise->Js.Promise.then_(callback), that is desugared to Js.Promise.then_(promise, callback). See the error?

1 Like

Oh I see. I should’ve properly read