I was looking at the definition of Js.String.get
in bucklescript/jscomp/others/js_string.ml
, which gives this signature:
external get : t -> int -> t = "" [@@bs.get_index]
This code: Js.log(Js.String.get("abc", 4))
prints out undefined
. A discussion in discord indicates that the signature is incorrect, and should be:
external get : t -> int -> t option = "" [@@bs.get_index][@@bs.return {undefined_to_opt}]
However, given the original signature: is there a way to find out in generic Reason code if a value returned from a JavaScript external function is null
or undefined
? Or should it be handled in the external signature by specifying nullable
?