Optional and nullable fields

Hello,

I’m trying to read some values from JS objects returned from javascript. I have flagged some fields as optional, but they are actually optional, nullable and a string.

This is a small example of what I have defined

[@bs.deriving abstract]
type args = {
  [@bs.optional] [@bs.as "<imageName>"]
  imageName: string,
  [@bs.as "<serviceName>"]
  serviceName: string
};

This is the generated JS code

function readName(args) {
  var match = args["<imageName>"];
  if (match !== undefined) {
    return /* Image */Block.__(0, [match]);
  } else {
    return /* Service */Block.__(1, [args["<serviceName>"]]);
  }
}

So when the value is null the strict undefined comparsion fails and I get a null value.
What should I do to prevent null and undefined ? Just making it nullable ?

Finally this is what I did
I declared the field as nullable using Js.nullable and then just read it using a function and pattern matching

[@bs.deriving abstract]
type args = {
  [@bs.as "<imageName>"]
  imageName: Js.nullable(string),
  [@bs.as "<serviceName>"]
  serviceName: string
};

Then just convert it to option and read

let readName = args =>
  switch ((args->imageNameGet) |> Js.toOption) {
  | Some(name) => Image(name)
  | None => Service(args->serviceNameGet)
  };

Is there a better way ? I would prefer a more streamline way…