Promise Data Type problem

I am sorry if this is a newbie non-rescript related question, but I cannot seem to find a solution to it.

I have a promise that fetches data from an API. I am looking to perform operation on the fetched value and return the value.

let value = APIPromise -> Js.Promise.then_(value => {
    Js.Promise.resolve(value+4)
},_)

The variable value will have the type Js.Promise.t<int> instead of int. How can I transform Js.Promise.t<int> to int? Thanks.

You need to use the value in the last then_ call. You can’t unwrap it like in your example. In JS, they have a special syntax called “async / await” to allow this kind of synchronous looking code, which is currently not implemented in ReScript.

3 Likes