From c1fc816cdb03f7c9ff2e6745ff38a2b4f119d556 Mon Sep 17 00:00:00 2001 From: Jason Quense Date: Fri, 12 Feb 2021 17:15:43 -0500 Subject: [PATCH] fix: schemaOf handles Dates --- src/index.ts | 4 ++++ test/types.ts | 3 +++ 2 files changed, 7 insertions(+) diff --git a/src/index.ts b/src/index.ts index 5c86cee62..c8b73406b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -40,6 +40,8 @@ type ObjectSchemaOf = ObjectSchema< { [k in keyof T]-?: T[k] extends Array ? ArraySchema | Lazy>> + : T[k] extends Date + ? DateSchema : T[k] extends AnyObject ? // we can't use ObjectSchema<{ []: SchemaOf }> b/c TS produces a union of two schema ObjectSchemaOf> @@ -49,6 +51,8 @@ type ObjectSchemaOf = ObjectSchema< type SchemaOf = T extends Array ? ArraySchema | Lazy>> + : T extends Date + ? DateSchema : T extends AnyObject ? ObjectSchemaOf : BaseSchema; diff --git a/test/types.ts b/test/types.ts index dfe20c555..d2d297764 100644 --- a/test/types.ts +++ b/test/types.ts @@ -10,6 +10,7 @@ import { ref, lazy, SchemaOf, + date, } from '../src'; import type { AssertsShape, @@ -220,6 +221,7 @@ SchemaOf: { title: string | undefined; age?: number; colors: string[]; + createdAt: Date; }; type PersonSchema = SchemaOf; @@ -229,6 +231,7 @@ SchemaOf: { title: string(), age: number(), colors: array(string().defined()), + createdAt: date().defined(), }); }