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 ?