I was surprised that the compiler didn’t complain about a missing age field in the following code:
type foo = {
name: string,
age: int,
};
let f: foo => unit =
foo => {
let {name} = foo;
Js.log(name);
};
Am I right that when you destructure a record in plan ocaml, you need to handle all the fields? Either way, is there a way to destructure a record s.t. the compiler will force you to handle all the fields?
In my experience, this is a valuable way for the compiler to help you after a record field is added. Let’s say you previously had a function that converted the record to a Js.Json.t
, it’d be nice if that function complained when you later added a new field to the record and haven’t yet updated the function to handle that field.