Skip to content

ValidatorContext ​

ValidatorContext holds contextual information during validation. It tracks the path of nested properties being validated and whether a value previously existed in the schema. This context is used internally by validators and by SchemaError to produce informative error messages.

Constructor ​

ts
declare class ValidatorContext {
    public constructor();
    public constructor(existed: boolean);
}

Parameters ​

ParameterTypeDescription
existedboolean | undefinedWhether the property existed in the object (distinguishes missing vs. undefined). Defaults to true.

Methods ​

createChild ​

ts
declare class ValidatorContext {
    public createChild(name: string | number, existed: boolean): ValidatorContext;
}

Creates a new ValidatorContext as a child of the current context, appending the given name to the validation path.

ts
const childContext = parentContext.createChild("fieldName", true);

Properties ​

PropertyTypeDescription
get pathstringDot-separated path of the current context in nested schemas.
get hasPathbooleanReturns true if the context has any path elements.
get existedbooleanIndicates the property existed in the object (distinguishes missing vs. undefined)