So bs.unwrap does unfortunately not work with @bs.obj. This means it also does not work with [@react.component] either, which uses @bs.obj internally, if you stumbled over that.
If you are on BuckleScript 7.1 or higher, there is an alternative, though: [@unboxed]:
For instance if you take the callbackOrButtons from above:
typebutton;moduleCallbackOrButtons={[@unboxed]typet=|Any('a):t;letmakeCallback:(.string=>unit)=>t=(.s)=>Any(s);letmakeButtons:array(button)=>t=i=>Any(i);};/* The Obj.magic is only for demonstration purposes,
I did not want to type out the button type. */letbuttons=CallbackOrButtons.makeButtons([|"<Button/>"->Obj.magic|])letcallback=CallbackOrButtons.makeCallback(.a=>Js.log(a))
then you would call ~callbackOrButtons=buttons or ~callbackOrButtons=callback in the binding from the article.
So bs.unwrap does unfortunately not work with
@bs.obj
. This means it also does not work with[@react.component]
either, which uses@bs.obj
internally, if you stumbled over that.It works perfectly in the source code of the example which does not use
@bs.obj
.If you are on BuckleScript 7.1 or higher, there is an alternative, though:
[@unboxed]
:For instance if you take the callbackOrButtons from above:
then you would call
~callbackOrButtons=buttons
or~callbackOrButtons=callback
in the binding from the article.Thank you, I will definitely try this.