Skip to content

Commit

Permalink
Fix array handling in SchemaOf type
Browse files Browse the repository at this point in the history
- Move array before object so that inference works correctly
- Include lazy as part of array type, to match the class definition
  • Loading branch information
chasecaleb committed Dec 10, 2020
1 parent ecad1a3 commit 6019641
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -37,11 +37,11 @@ function addMethod(schemaType: any, name: string, fn: any) {
schemaType.prototype[name] = fn;
}

type SchemaOf<T> = T extends AnyObject
? ObjectSchema<{ [k in keyof T]: SchemaOf<T[k]> }>
: T extends Array<infer E>
? ArraySchema<SchemaOf<E>>
: BaseSchema<Maybe<T>, AnyObject, T>;
type SchemaOf<T> = T extends Array<infer E>
? ArraySchema<SchemaOf<E> | Lazy<SchemaOf<E>>>
: T extends AnyObject
? ObjectSchema<{ [K in keyof T]: SchemaOf<T[K]> }>
: BaseSchema<Maybe<T>, AnyObject, T>;

export type AnyObjectSchema = ObjectSchema<any, any, any, any>;
export type { SchemaOf, TypeOf, Asserts, Asserts as InferType, AnySchema };
Expand Down

0 comments on commit 6019641

Please sign in to comment.