Hello I am a freshman,and I have a problem on learning.
in Javascript, sometimes we use default value with destructuring, like this:
let {width = 100, height = 200, title} = options
and in Rescript I try to use a record to describe the config options with optional record fields,But when I try to destructuring:
type options = {
width?: int,
height?: int,
}
let test = (options: options) => {
let {width, height} = options
}
it will remind me “forgot to handle a possible case here”, But i don’t know how to solve and give a default value. Could anyone give me some tips? would it better to bind the let one by one? is that a surgar of pattern matching similar to below and how to solve elegant?
type options = {
width?: int,
height?: int,
}
let test = (options: options) => {
let {width, height} = switch options{
|{width:Some("dont know what to fill"),height:None}=>{"balabala"}
|{width:None,height:Some("dont know what to fill")}=>{"balabala"}
|{width:Some("dont know what to fill"),height:Some("dont know what to fill")}=>{"balabala"}
|{width:None,height:None}=>{"balabala"}
}