Optional / null values
const pet = M.fromJSON(Animal, '{"name": null}')
// => TypeError: no value for key "name"Using withDefault
withDefaultimport M from 'modelico'
const {string, maybe} = M.metadata()
class Animal extends M.Base {
// ... same as before
static innerTypes () {
return Object.freeze({
name: withDefault(string(), 'Unknown')
})
}
}Maybes
Last updated