Libraries
    Preparing search index...

    Type Alias PropertySetterOptions

    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:

    const schema = object({
    name: string(),
    address: object({
    city: string(),
    country: string()
    }),
    id: number()
    });

    then you can get a property descriptor for the address.city property like this:

    const addressCityDescriptor = object.getPropertiesFor(schema).address.city;
    

    And then you can use it to get and set the value of this property having the object:

    const obj = {
    name: 'Leo',
    address: {
    city: 'Kozelsk',
    country: 'Russia'
    },
    id: 123
    };

    const success = addressCityDescriptor.setValue(obj, 'Venyov');
    // this returns you a boolean value indicating if the value was set successfully
    type PropertySetterOptions = {
        createMissingStructure?: boolean;
    }
    Index

    Properties

    createMissingStructure?: boolean

    If 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'
    // }