Closed jchavarri closed 2 years ago
Ops, that's because the type is enforced by HTML. Should we allow to be wrapped with option?
It's relatively easy to do!
I think it'd be useful :) The sample code I was working on had either href
or onClick
depending on some optional value. We can work around it by building two elements, one with href
and one with onClick
, but it's kind of sad to not be able to leverage optional labelled args, no? (if you say it's easy...)
@davesnx it seems this is still not possible.
Input:
let href = None
let element = a ?href ()
^^^^^^^^^^
Error: This expression has type string option
but an expression was expected of type string
make: *** [build] Error 1
If I expand the expression:
let element =
React.Dom.createDOMElementVariadic "a"
~props:(Js_of_ocaml.Js.Unsafe.obj
[|("href",
(Js_of_ocaml.Js.Unsafe.inject
(Js_of_ocaml.Js.Optdef.option
(Js_of_ocaml.Js.string (href : string option)))))|] :
^^^^^^^^^^^^^^^^^^^^^^
Error: This expression has type string option
but an expression was expected of type string
make: *** [build] Error 1
React.Dom.domProps) []
(we should prob add a test to test_jsoo_react
suite)
This was fixed in https://github.com/ml-in-barcelona/jsoo-react/pull/92. Thanks @davesnx !
Repro: