I have:
type xyz = {
a: int,
b: option<string>
}
I could also do
type xyz = {
a: int,
b?: string
}
Which approach is would you use where?
I my case xyz is my own code and not part of a binding.
It is also not a props records.
I have:
type xyz = {
a: int,
b: option<string>
}
I could also do
type xyz = {
a: int,
b?: string
}
Which approach is would you use where?
I my case xyz is my own code and not part of a binding.
It is also not a props records.
Personally I only use the optional fields for JS interop, most prominently option objects where usually everything is optional.
I still prefer the strictness of explicitly defined options even if that means that an “empty” instantiation is full of None’s. It’s similar to writing down the cases of a variant explicitly so that you can not forget to handle it when you add a new variant case.