Hello.
I’m trying to write bindings for ags ags docs
type baseProps = {
name: string
}
module Label = {
type t
type props = {
...baseProps,
label?: string,
}
@val @scope("Widget") external make: props => t = "Label"
}
module Box = {
type t
type widget = | Label(Label.t) | Box(t) // and more
type props = {
...baseProps, // and additional optional fields
child?: widget,
children?: array<widget>,
}
@val @scope("Widget") external make: props => t = "Box"
}
I have to unwrap child and children somehow. If I’m right, I can use @unwrap this way
type baseProps = {
"name": string
}
module Label = {
type t = {
widgetType: string,
}
type props = {
...baseProps,
label?: string,
}
@val @scope("Widget") external make: props => t = "Label"
}
module Box = {
type t
@val @scope("Widget") external make: {
...baseProps,
"child": @unwrap [#Label(Label.t) | #Box(t) ],
"children": array<@unwrap [#Label(Label.t) | #Box(t) ]>,
} => t = "Box"
}
But in this case I can’t make fields optional. How can I solve it?
Perhaps I can write something like
module Box = {
type t
@val @scope("Widget") external make: {
"name": option<string>,
"child": option<@unwrap [#Label(Label.t) | #Box(t) ]>,
"children": option<array<@unwrap [#Label(Label.t) | #Box(t) ]>>,
} => t = "Box"
}
but it will be annoying