diff --git a/src/array.ts b/src/array.ts index c42fd31a4..3d73101c3 100644 --- a/src/array.ts +++ b/src/array.ts @@ -269,8 +269,9 @@ export default class ArraySchema< } describe(options?: ResolveOptions) { - let base = super.describe(options) as SchemaInnerTypeDescription; - if (this.innerType) { + const next = (options ? this.resolve(options) : this).clone(); + const base = super.describe(options) as SchemaInnerTypeDescription; + if (next.innerType) { let innerOptions = options; if (innerOptions?.value) { innerOptions = { @@ -279,7 +280,7 @@ export default class ArraySchema< value: innerOptions.value[0], }; } - base.innerType = this.innerType.describe(innerOptions); + base.innerType = next.innerType.describe(innerOptions); } return base; } diff --git a/src/object.ts b/src/object.ts index 39e921cc0..cbc583e5e 100644 --- a/src/object.ts +++ b/src/object.ts @@ -514,9 +514,10 @@ export default class ObjectSchema< } describe(options?: ResolveOptions) { - let base = super.describe(options) as SchemaObjectDescription; + const next = (options ? this.resolve(options) : this).clone(); + const base = super.describe(options) as SchemaObjectDescription; base.fields = {}; - for (const [key, value] of Object.entries(this.fields)) { + for (const [key, value] of Object.entries(next.fields)) { let innerOptions = options; if (innerOptions?.value) { innerOptions = { diff --git a/src/tuple.ts b/src/tuple.ts index e3e0ce6e9..f4bf6443d 100644 --- a/src/tuple.ts +++ b/src/tuple.ts @@ -160,8 +160,9 @@ export default class TupleSchema< } describe(options?: ResolveOptions) { - let base = super.describe(options) as SchemaInnerTypeDescription; - base.innerType = this.spec.types.map((schema, index) => { + const next = (options ? this.resolve(options) : this).clone(); + const base = super.describe(options) as SchemaInnerTypeDescription; + base.innerType = next.spec.types.map((schema, index) => { let innerOptions = options; if (innerOptions?.value) { innerOptions = { diff --git a/test/mixed.ts b/test/mixed.ts index f1848e50f..687476b9f 100644 --- a/test/mixed.ts +++ b/test/mixed.ts @@ -967,6 +967,11 @@ describe('Mixed Types ', () => { then: (s) => s.defined(), }), baz: tuple([string(), number()]), + }) + .when(['dummy'], (_, s) => { + return s.shape({ + when: string() + }) }); }); @@ -1087,6 +1092,7 @@ describe('Mixed Types ', () => { bar: 'a', lazy: undefined, baz: undefined, + when: undefined, }, nullable: false, optional: true, @@ -1185,6 +1191,17 @@ describe('Mixed Types ', () => { }, ], }, + when: { + type: 'string', + meta: undefined, + label: undefined, + default: undefined, + notOneOf: [], + nullable: false, + oneOf: [], + optional: true, + tests: [], + } }, }); });