Option, undefined and return(undefined_to_opt)

Consider these bindings:

@send external get1: (map<'v>, string) => Js.undefined<'v> = "get"
@send external get2: (map<'v>, string) => option<'v> = "get"
@send @return(undefined_to_opt) external get3: (map<'v>, string) => option<'v> = "get"

get1 would require a wrapper to convert undefined to option. I understand it is not recommended to annotate get2 with type parameter, per Caveat 1

Does the @return in get3 patch Caveat 1? When is @return(undefined_to_opt) used in general? For example, why

@send @return(undefined_to_opt) external getInt1: (map<int>, string) => option<int> = "get"

instead of

@send external getInt1: (map<int>, string) => option<int> = "get"

?

hi @quanganhtran sorry for the late reply.
It depends on your specific bindings.
For type option<'a> when 'a is primitive type, for example string, int, function, option<'a> is the same as 'a|undefined.
If you bindings indeed return int|undefined, this is exactly the same as option<int>, so no wrapper needed for this case.

It is recommended to write your bindings with a specific type if possible.

If you are unclear what’s going on, you are encouraged to read the generated code in the call site.