Repository: jquense/yup (ts)

Issue:
Something is wrong with dates and TypeScript support.
**Describe the bug**
The following typescript errors appear:
```typescript
import * as Yup from 'yup';
import {SchemaOf, Asserts} from 'yup';

// TEST 1

const schema1 = Yup.object({
  date: Yup.date().defined()
}).defined();

type Type1 = Asserts<typeof schema1>;

function test1(schema: SchemaOf<Type1>) {

}

test1(schema1); // TS error
// Argument of type 'DefinedObjectSchema<{ date: DefinedDateSchema<Date | undefined, Record<string, any>>; }, Record<string, any>, TypeOfShape<{ date: DefinedDateSchema<Date | undefined, Record<...>>; }>>' is not assignable to parameter of type 'ObjectSchemaOf<AssertsShape<{ date: DefinedDateSchema<Date | undefined, Record<string, any>>; }>>'.
//  The types of 'fields.date' are incompatible between these types.
//    Type 'DefinedDateSchema<Date | undefined, Record<string, any>>' is missing the following properties from type 'ObjectSchema<{ toString: ObjectSchemaOf<() => string>; toDateString: ObjectSchemaOf<() => string>; toTimeString: ObjectSchemaOf<() => string>; toLocaleString: ObjectSchemaOf<...>; ... 38 more ...; toJSON: ObjectSchemaOf<...>; }, Record<...>, TypeOfShape<...>, AssertsShape<...>>': fields, _sortErrors, _nodes, _excludedEdges, and 11 more.ts(2345)

// TEST 2

interface Type2 {
  date: Date;
}

const schema2: SchemaOf<Type2> = Yup.object({ // TS ERROR
  date: Yup.date().defined()
}).defined();
// Type 'DefinedObjectSchema<{ date: DefinedDateSchema<Date | undefined, Record<string, any>>; }, Record<string, any>, TypeOfShape<{ date: DefinedDateSchema<Date | undefined, Record<...>>; }>>' is not assignable to type 'ObjectSchemaOf<Test2>'.
//   The types of 'fields.date' are incompatible between these types.
//     Type 'DefinedDateSchema<Date | undefined, Record<string, any>>' is not assignable to type 'ObjectSchemaOf<Date>'.ts(2322)


function test2(schema: SchemaOf<Type2>) {

}

test2(schema2);
```

**To Reproduce**
https://codesandbox.io/s/yup-dates-typescript-l4kon?file=/src/index.ts

**Expected behavior**
There should be no typescript errors for this example.

**Platform (please complete the following information):**
 - Firefox
 - 85.0


Pull request description:
Fix SchemaOf<>'s treatment of Date objects.
Resolve #1243 and #1302.

Add a test for SchemaOf containing Date objects
and an array of date objects.

Patch:
diff --git a/src/index.ts b/src/index.ts
index 26f41e0..cc97f42 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -41,6 +41,8 @@ type ObjectSchemaOf<T extends AnyObject> = ObjectSchema<
   {
     [k in keyof T]-?: T[k] extends Array<infer E>
       ? ArraySchema<SchemaOf<E> | Lazy<SchemaOf<E>>>
+      : T[k] extends Date
+      ? BaseSchema<Maybe<T[k]>, AnyObject, T[k]>
       : T[k] extends AnyObject
       ? // we can't use  ObjectSchema<{ []: SchemaOf<T[k]> }> b/c TS produces a union of two schema
         ObjectSchemaOf<T[k]> | ObjectSchemaOf<Lazy<T[k]>>
@@ -50,6 +52,8 @@ type ObjectSchemaOf<T extends AnyObject> = ObjectSchema<
 
 type SchemaOf<T> = T extends Array<infer E>
   ? ArraySchema<SchemaOf<E> | Lazy<SchemaOf<E>>>
+  : T extends Date
+  ? BaseSchema<Maybe<T>, AnyObject, T>
   : T extends AnyObject
   ? ObjectSchemaOf<T>
   : BaseSchema<Maybe<T>, AnyObject, T>;


Test patch:
diff --git a/test/types.ts b/test/types.ts
index 5a0c300..4383f0d 100644
--- a/test/types.ts
+++ b/test/types.ts
@@ -10,6 +10,7 @@ import {
   mixed,
   number,
   ref,
+  date,
   lazy,
   SchemaOf,
 } from '../src';
@@ -201,6 +202,35 @@ SchemaOf: {
   });
 }
 
+SchemaOfDate: {
+  type Employee = {
+    hire_date: Date;
+    name: string;
+  };
+
+  type EmployeeSchema = SchemaOf<Employee>;
+
+  const _t: EmployeeSchema = object({
+    name: string().defined(),
+    hire_date: date().defined()
+  });
+}
+
+SchemaOfDateArray: {
+  type EmployeeWithPromotions = {
+    promotion_dates: Date[];
+    name: string;
+  };
+
+  type EmployeeWithPromotionsSchema = SchemaOf<EmployeeWithPromotions>;
+
+  const _t: EmployeeWithPromotionsSchema = object({
+    name: string().defined(),
+    promotion_dates: array().of(date().defined())
+  });
+}
+
+
 {
   // const str = string();
   // type f = Type<typeof str>;