OptionalcreateIf set to true, the method will create missing structure
in the object to set the value. For example, if you have a schema
and property descriptor like this:
const schema = object({
address: object({
city: string(),
country: string()
}),
});
const addressCityDescriptor = object.getPropertiesFor(schema).address.city;
And then you try to set a new value to the address.city property on the object
which does not have address property:
const obj = {
name: 'Leo'
};
const success = addressCityDescriptor.setValue(obj, 'Venyov', { createMissingStructure: true });
// success === true
// obj === {
// name: 'Leo',
// address: {
// city: 'Venyov'
// }
Describes a property in a schema. And gives you a possibility to access property value and set it. suppose you have a schema like this:
then you can get a property descriptor for the
address.cityproperty like this:And then you can use it to get and set the value of this property having the object: