Possible bug in Js.Promise2.then and Js.Promise2.catch

I was getting some odd runtime type errors while switch from Js.Promise to Js.Promise2. So looking at the file js_promise2.res, I see the following:

/** Type-safe t-first then */
let then: (promise<'a>, 'a => promise<'b>) => promise<'b> = %raw(`
  function(p, cont) {
    Promise.resolve(p).then(cont)
  }
  `)

/** Type-safe t-first catch */
let catch: (promise<'a>, error => promise<'a>) => promise<'a> = %raw(`
    function(p, cont) {
      Promise.resolve(p).catch(cont)
    }
    `)

Notice that those functions lack a return, so they fail to actually return anything.

This was already addressed: Promise returned undefined instead of value (10.0.1 & 10.1.1) · Issue #5958 · rescript-lang/rescript-compiler · GitHub

1 Like