How to call a JS method called "val"


Hi, just starting out with ReasonML. I’m trying to model a JS class (from the Firebase API) as follows:

type dataSnapshot('k, 'v) = {
  "key": 'k,
  [@bs.meth] "val": unit => Js.Nullable.t('v),
  [@bs.meth] "exists": unit => bool,
  [@bs.meth] "numChildren": unit => int,

open ReasonMaybe;

let snapValMaybe = (snapshot: option(dataSnapshot('k, 'v))) =>
  |> Maybe.chain(snap => Maybe.from(Js.Nullable.toOption(snap##val())));

But snap##val() is a syntax error, presumably because val is a reserved word. I can’t use [] for some reason – perhaps because I am already using the quoted object keys syntax?

Any help or insight would be hugely appreciated. Thanks!


Have you tried snap##_val? From my experience, if a certain parameter name is invalid or reserved in Reason, prepending an underscore allows it to compile.


Thanks for this, and sorry for the delay in replying. I’ve actually rewritten the model to use [@bs.send], which I think is a more idiomatic ReasonML approach.