Hi @mouton did you have any success with this?
Not sure if this will help, but I’ll offer a few thoughts.
I’m assuming you would like to do something like the Highcharts React example (but presumably a more complex version):
const options = {
title: {
text: 'My chart'
},
series: [{
data: [1, 2, 3]
}]
}
const App = () => (
<div>
<HighchartsReact
highcharts={Highcharts}
options={options}
/>
</div>
);
The first option that you might have already considered is to use a ReScript object:
let options = {
"title": {
"text": "My chart",
},
"series": [
{
"data": [1, 2, 3],
},
],
}
Which produces:
var options = {
title: {
text: "My chart",
},
series: [
{
data: [1, 2, 3],
},
],
};
We don’t get type safety here, but it’s simple and might be a good option if your risk of errors is low.
Another option may be to use the @obj
decorator:
module Options = {
type t
type title
type series
@obj external title: (~text: string) => title = ""
@obj external series: (~data: array<int>) => series = ""
@obj external make: (~title: title=?, ~series: array<series>=?) => t = ""
}
let options = Options.make(
~title=Options.title(~text="My chart"),
~series=[Options.series(~data=[1, 2, 3])],
)
Which produces the same:
var options = {
title: {
text: "My chart",
},
series: [
{
data: [1, 2, 3],
},
],
};
I tried using @unwrap
with @react.component
but I wasn’t able to get that working.
Also see this previous post by @tsnobip which also described a similar problem.
Edit: You mentioned some of the options are polymorphic. Do you have an example of one of those options?