2

When making a promise in Rescript:

let myPromise = Js.Promise.make((~resolve, ~reject) => resolve(. 2))

The ReScript compiler will give a warning on unused variable reject.

Is there a way to suppress this error?

glennsl
  • 28,186
  • 12
  • 57
  • 75
heiheihang
  • 82
  • 9
  • I haven't used rescript, but can you just use `.make((~resolve) =>`? – jonrsharpe Apr 07 '21 at 07:59
  • `.make()` is a built in function from ReScript's JS API and it must take 2 named arguments `resolve` and `reject`. It is necessary to follow the format in ReScript or else the compiler will be unhappy. – heiheihang Apr 08 '21 at 04:01

1 Answers1

5

You can bind a parameter to a new name using as, i.e. ~reject as newName, and as with any binding/pattern you can use the wildcard pattern, _, to tell the compiler that you're intentionally ignoring it.

So put together it'd be:

let myPromise = Js.Promise.make((~resolve, ~reject as _) => resolve(. 2))
glennsl
  • 28,186
  • 12
  • 57
  • 75