Looks like a bug, but I am not sure. Somebody can shed some light on this.
Consider the below code. In the below code, a promise
holds an option
which again holds another promise
. Now if I have to change the value in the inner most promise
, then the natural way to do it is to write a then_
for first promise, a map
on the option and a then_
on the inner most promise.
let opPromise: option<Js.Promise.t<int>> =
Some(Js.Promise.resolve(1))
let promiseOpPromise: Js.Promise.t<option<Js.Promise.t<int>>> =
Js.Promise.resolve(opPromise)
let _ = {
// First promise
Js.Promise.then_(d =>
Js.Promise.resolve(
// Option
Belt.Option.map(
d,
// Inner most promise
Js.Promise.then_(f => Js.Promise.resolve(f + 1)),
),
)
, promiseOpPromise)
}
This code compiles fine. But will throw the below error if you try to run it.
(node:18716) UnhandledPromiseRejectionWarning: TypeError: param.then is not a function
I am not sure why this is happening. Please advise.