diff --git a/src/index.ts b/src/index.ts index 1bf992f43..97ae53eef 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,7 +6,7 @@ import DateSchema, { create as dateCreate } from './date'; import ObjectSchema, { AnyObject, create as objectCreate } from './object'; import ArraySchema, { create as arrayCreate } from './array'; import { create as refCreate } from './Reference'; -import { create as lazyCreate } from './Lazy'; +import Lazy, { create as lazyCreate } from './Lazy'; import ValidationError from './ValidationError'; import reach from './util/reach'; import isSchema from './util/isSchema'; @@ -39,20 +39,20 @@ function addMethod(schemaType: any, name: string, fn: any) { type ObjectSchemaOf = ObjectSchema< { - [k in keyof T]-?: T[k] extends AnyObject + [k in keyof T]-?: T[k] extends Array + ? ArraySchema> + : T[k] extends AnyObject ? // we can't use ObjectSchema<{ []: SchemaOf }> b/c TS produces a union of two schema ObjectSchemaOf - : T[k] extends Array - ? ArraySchema> : BaseSchema, AnyObject, T[k]>; } >; -type SchemaOf = T extends AnyObject - ? ObjectSchemaOf - : T extends Array - ? ArraySchema> - : BaseSchema, AnyObject, T>; +type SchemaOf = T extends Array + ? ArraySchema | Lazy>> + : T extends AnyObject + ? ObjectSchemaOf + : BaseSchema, AnyObject, T>; export type AnyObjectSchema = ObjectSchema;