Libraries
    Preparing search index...

    Type Alias PropertyDescriptorInner<TSchema, TPropertySchema, TParentPropertyDescriptor>

    type PropertyDescriptorInner<
        TSchema extends ObjectSchemaBuilder<any, any, any, any, any>,
        TPropertySchema,
        TParentPropertyDescriptor,
    > = {
        getSchema: () => TPropertySchema;
        getValue: (
            obj: InferType<TSchema>,
        ) => { success: boolean; value?: InferType<TPropertySchema> };
        parent: PropertyDescriptorInnerFromPropertyDescriptor<
            TParentPropertyDescriptor,
        >;
        setValue: (
            obj: InferType<TSchema>,
            value: InferType<TPropertySchema>,
            options?: PropertySetterOptions,
        ) => boolean;
    }

    Type Parameters

    • TSchema extends ObjectSchemaBuilder<any, any, any, any, any>
    • TPropertySchema
    • TParentPropertyDescriptor
    Index

    Properties

    getSchema: () => TPropertySchema

    Gets the schema for the property described by the property descriptor.

    Type Declaration

    getValue: (
        obj: InferType<TSchema>,
    ) => { success: boolean; value?: InferType<TPropertySchema> }

    Gets the value of the property from the object.

    Type Declaration

      • (
            obj: InferType<TSchema>,
        ): { success: boolean; value?: InferType<TPropertySchema> }
      • Parameters

        Returns { success: boolean; value?: InferType<TPropertySchema> }

        an object containing a value and success properties. value is the value of the property if it was found in the object, success is a boolean value indicating if the property was found in the object.

    parent: PropertyDescriptorInnerFromPropertyDescriptor<TParentPropertyDescriptor>
    setValue: (
        obj: InferType<TSchema>,
        value: InferType<TPropertySchema>,
        options?: PropertySetterOptions,
    ) => boolean

    Sets a new value to the property. If the process was successful, the method returns true, otherwise false. It can return false if the property could not be set to the object which can happen if the setValue method is called with an object which does not comply with the schema. for example, if you have a schema and property descriptopr like this:

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

    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');
    // success === false

    Type Declaration