type xEntry = {title: string};
type yEntry = {value: int};
type entry =
| X(xEntry)
| Y(yEntry);
[@bs.deriving abstract]
type jsXEntry = {
[@bs.as "type"]
type_: string,
title: string,
};
[@bs.deriving abstract]
type jsYEntry = {
[@bs.as "type"]
type_: string,
value: int,
};
type jsEntry =
| JsX(jsXEntry)
| JsY(jsYEntry);
let fromEntry = entry =>
switch (entry) {
| X(v) => JsX(jsXEntry(~type_="X", ~title=v.title))
| Y(v) => JsY(jsYEntry(~type_="Y", ~value=v.value))
};
let convertToJs = (entries: list(entry)): Js.Array.t(jsEntry) =>
Array.map(fromEntry, ArrayLabels.of_list(entries));
let value = [
X({title: "foo"}),
Y({value: 123})
];
Js.log(convertToJs(value));