Repository: jquense/yup
Pull request #1148 (2020-12-04 21:52:07)

Add additional functions to Lazy class
Add missing functions to Lazy:

    isValid
    isValidSync
    isType

These are all validation functions that have a value parameter, so it makes sense for Lazy to wrap them.


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index aeb206d..a5f49a3 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,25 @@
+## [0.32.3](https://github.com/jquense/yup/compare/v0.32.2...v0.32.3) (2020-12-07)
+
+
+### Bug Fixes
+
+* **types:** AnyObjectSchema anys ([1c54665](https://github.com/jquense/yup/commit/1c54665))
+
+
+
+
+
+## [0.32.2](https://github.com/jquense/yup/compare/v0.32.1...v0.32.2) (2020-12-07)
+
+
+### Bug Fixes
+
+* **types:** array type with lazy ([ba92dfc](https://github.com/jquense/yup/commit/ba92dfc)), closes [#1146](https://github.com/jquense/yup/issues/1146)
+
+
+
+
+
 ## [0.32.1](https://github.com/jquense/yup/compare/v0.32.0...v0.32.1) (2020-12-04)
 
 
diff --git a/README.md b/README.md
index c895733..b894470 100644
--- a/README.md
+++ b/README.md
@@ -802,7 +802,7 @@ date parsing strategy than the default one you could do that with a transform.
 
 ```js
 module.exports = function (formats = 'MMM dd, yyyy') {
-  return date().transform(function (value, originalvalue) {
+  return date().transform(function (value, originalValue) {
     // check to see if the previous transform already parsed the date
     if (this.isType(value)) return value;
 
diff --git a/package.json b/package.json
index 3c768c4..d0c6051 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "yup",
-  "version": "0.32.1",
+  "version": "0.32.3",
   "description": "Dead simple Object schema validation",
   "main": "lib/index.js",
   "module": "es/index.js",
diff --git a/src/Lazy.ts b/src/Lazy.ts
index 8aaad37..f49cb74 100644
--- a/src/Lazy.ts
+++ b/src/Lazy.ts
@@ -82,6 +82,13 @@ class Lazy<T extends AnySchema, TContext = ContextOf<T>>
   describe() {
     return null as any;
   }
+
+  isValid(value: any, options?: ValidateOptions<TContext>) {
+    return this._resolve(value, options).isValid(value, options);
+  }
+  isValidSync(value: any, options?: ValidateOptions<TContext>) {
+    return this._resolve(value, options).isValidSync(value, options);
+  }
 }
 
 export default Lazy;
diff --git a/src/array.ts b/src/array.ts
index b56daed..8ffaaab 100644
--- a/src/array.ts
+++ b/src/array.ts
@@ -20,18 +20,19 @@ import BaseSchema, {
   SchemaInnerTypeDescription,
   SchemaSpec,
 } from './schema';
+import Lazy from './Lazy';
 
 export type RejectorFn = (value: any, index: number, array: any[]) => boolean;
 
 export function create<
   C extends AnyObject = AnyObject,
-  T extends AnySchema = AnySchema
+  T extends AnySchema | Lazy<any, any> = AnySchema
 >(type?: T) {
   return new ArraySchema<T, C>(type) as OptionalArraySchema<T, C>;
 }
 
 export default class ArraySchema<
-  T extends AnySchema,
+  T extends AnySchema | Lazy<any, any>,
   C extends AnyObject = AnyObject,
   TIn extends Maybe<TypeOf<T>[]> = TypeOf<T>[] | undefined,
   TOut extends Maybe<Asserts<T>[]> = Asserts<T>[] | Optionals<TIn>
@@ -135,13 +136,7 @@ export default class ArraySchema<
           originalValue: originalValue[idx],
         };
 
-        tests[idx] = (_, cb) =>
-          innerType!.validate(
-            item,
-            innerOptions,
-            // @ts-expect-error
-            cb,
-          );
+        tests[idx] = (_, cb) => innerType!.validate(item, innerOptions, cb);
       }
 
       runTests(
@@ -175,7 +170,8 @@ export default class ArraySchema<
 
     if (schema.innerType)
       next.innerType = next.innerType
-        ? next.innerType.concat(schema.innerType)
+        ? // @ts-expect-error Lazy doesn't have concat()
+          next.innerType.concat(schema.innerType)
         : schema.innerType;
 
     return next;
@@ -274,7 +270,7 @@ create.prototype = ArraySchema.prototype;
 //
 
 export interface DefinedArraySchema<
-  T extends AnySchema,
+  T extends AnySchema | Lazy<any, any>,
   TContext extends AnyObject,
   TIn extends Maybe<TypeOf<T>[]>
 > extends ArraySchema<T, TContext, TIn, Asserts<T>[] | Preserve<TIn, null>> {
@@ -299,7 +295,7 @@ export interface DefinedArraySchema<
 }
 
 export interface RequiredArraySchema<
-  T extends AnySchema,
+  T extends AnySchema | Lazy<any, any>,
   TContext extends AnyObject,
   TIn extends Maybe<TypeOf<T>[]>
 > extends ArraySchema<T, TContext, TIn, Asserts<T>[]> {
@@ -322,7 +318,7 @@ export interface RequiredArraySchema<
 }
 
 export interface OptionalArraySchema<
-  T extends AnySchema,
+  T extends AnySchema | Lazy<any, any>,
   TContext extends AnyObject = AnyObject,
   TIn extends Maybe<TypeOf<T>[]> = TypeOf<T>[] | undefined
 > extends ArraySchema<T, TContext, TIn> {
diff --git a/src/index.ts b/src/index.ts
index c1698ee..92a0258 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -43,6 +43,7 @@ type SchemaOf<T> = T extends AnyObject
   ? ArraySchema<SchemaOf<E>>
   : BaseSchema<Maybe<T>, AnyObject, T>;
 
+export type AnyObjectSchema = ObjectSchema<any, any, any, any>;
 export type { SchemaOf, TypeOf, Asserts, Asserts as InferType, AnySchema };
 
 export {


Test patch:
diff --git a/test/types.ts b/test/types.ts
index 2c817bc..d7f29d4 100644
--- a/test/types.ts
+++ b/test/types.ts
@@ -228,6 +228,9 @@ SchemaOf: {
     .default(() => [] as string[])
     .validateSync(null);
 
+  // $ExpectType string[] | undefined
+  array(lazy(() => string().default(''))).validateSync(null);
+
   const numList = [1, 2];
 
   // $ExpectType (number | undefined)[]