diff --git a/src/index.ts b/src/index.ts index e8226ad67..8300d83d6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -18,6 +18,7 @@ import isSchema from './util/isSchema'; import setLocale, { LocaleObject } from './setLocale'; import Schema, { AnySchema, + CastOptions as BaseCastOptions, SchemaRefDescription, SchemaInnerTypeDescription, SchemaObjectDescription, @@ -51,6 +52,8 @@ function addMethod(schemaType: any, name: string, fn: any) { export type AnyObjectSchema = ObjectSchema; +export type CastOptions = Omit; + export type { AnyObject, InferType, @@ -67,7 +70,7 @@ export type { SchemaFieldDescription, SchemaDescription, LocaleObject, - ValidateOptions + ValidateOptions, }; export { diff --git a/src/object.ts b/src/object.ts index fbdcc00fb..dc5ce2ac0 100644 --- a/src/object.ts +++ b/src/object.ts @@ -183,7 +183,6 @@ export default class ObjectSchema< // safe to mutate since this is fired in sequence innerOptions.path = (options.path ? `${options.path}.` : '') + prop; - // innerOptions.value = value[prop]; field = field.resolve({ value: inputValue, @@ -268,9 +267,13 @@ export default class ObjectSchema< ); } - this.runTests({ tests, value }, panic, (fieldErrors) => { - next(fieldErrors.sort(this._sortErrors).concat(objectErrors), value); - }); + this.runTests( + { tests, value, originalValue, options }, + panic, + (fieldErrors) => { + next(fieldErrors.sort(this._sortErrors).concat(objectErrors), value); + }, + ); }); } diff --git a/src/schema.ts b/src/schema.ts index 92b696452..8d0f65d99 100644 --- a/src/schema.ts +++ b/src/schema.ts @@ -67,6 +67,7 @@ export interface CastOptions { stripUnknown?: boolean; // XXX: should be private? path?: string; + resolved?: boolean; } export interface CastOptionalityOptions @@ -449,9 +450,7 @@ export default abstract class Schema< /** * Executes a set of validations, either schema, produced Tests or a nested - * schema validate result. `args` is intended for schema validation tests, but - * isn't required to allow the helper to awkwardly be used to run nested array/object - * validations. + * schema validate result. */ protected runTests( runOptions: TestRunOptions,