-
Notifications
You must be signed in to change notification settings - Fork 456
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[@bs.as] for special BS object creation function #2614
Comments
Love the idea, but slightly concerned about overloading the meaning of |
The main thing is if we infer the output type still as The only sensible way to me is require the output to be an abstract type. By tweaking the spec of bs.deriving abstract, we are quite close to it: type label = {
high : int [@bs.as "high-value"];
low : int [@bs.optional]; (* better name or just use `int option` *)
} [@@bs.deriving abstract] In that case, we derive such functions: val label : high : int -> ?low: int -> unit -> label
val high : label -> int
val low : label -> int option So we need implement For bs.as, the rough idea is external label : high:int -> low: int -> label = "xxx" (* the internal encoding changed to "high-value" *)
external high : label -> ( _ : [@bs.as "high-value"]) -> int = "" [@@bs.get_index] For bs.optional, the rough idea is external label : high: int -> ?low: int -> label = "" [@@bs.obj]
external low : label -> int = "low" [@@bs.return undefined_to_opt] The two attributes may interact, this is quite a few work, lets make it for next release |
relevant to #2583 |
Currently type x = { hi: int} [@@bs.deriving {abstract = constructorName, "make"}] What do you think? |
It'd generate
{"high-value": 3}
.Super useful. The special object creation is the only one that allows optional fields, so we can't directly create the objs on the Reason side through
{"high-value": 3}
. For example: https://github.com/reasonml/reason-react/blob/7eed3579ebfc7402eebe331b740b0a8bed4e44b5/src/ReactDOMRe.re#L95cc @rickyvetter @thangngoc89 @yawaramin @glennsl
The text was updated successfully, but these errors were encountered: