Repository: jquense/yup
Pull request #1170 (2020-12-10 21:38:25)

Fix ObjectSchemaOf type definition
Follow up to #1169, because in my haste to rebase I overlooked adding `Lazy` to the `ArraySchema` generic in `ObjectSchemaOf`. I also simplified the `ObjectSchemaOf` definition since it doesn't need to repeat the `SchemaOf` definition. I also fixed my incorrect formatting from #1169.

I've tested this against my own project via `yarn link` so I know it at least works for my use cases.

jquense: I actually don't think you want to add the Lazy here. What is the use case? 

Patch:
diff --git a/docs/extending.md b/docs/extending.md
index 0ab60bc..d7129e2 100644
--- a/docs/extending.md
+++ b/docs/extending.md
@@ -43,7 +43,7 @@ yup.addMethod(yup.date, 'format', parseDateFromFormats);
 Note that `addMethod` isn't magic, it mutates the prototype of the passed in schema.
 
 > Note: if you are using TypeScript you also need to adjust the class or interface
-> see the [typescript](./typescript) docs for details.
+> see the [typescript](./typescript.md) docs for details.
 
 ## Creating new Schema types
 
diff --git a/package.json b/package.json
index 5b56d17..57dc1eb 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "yup",
-  "version": "0.32.6",
+  "version": "0.32.8",
   "description": "Dead simple Object schema validation",
   "main": "lib/index.js",
   "module": "es/index.js",
@@ -111,7 +111,7 @@
     "@babel/runtime": "^7.10.5",
     "@types/lodash": "^4.14.165",
     "lodash": "^4.17.20",
-    "lodash-es": "^4.17.11",
+    "lodash-es": "^4.17.15",
     "nanoclone": "^0.2.1",
     "property-expr": "^2.0.4",
     "toposort": "^2.0.2"
diff --git a/src/Reference.ts b/src/Reference.ts
index c57b472..0f81d81 100644
--- a/src/Reference.ts
+++ b/src/Reference.ts
@@ -10,8 +10,8 @@ export type ReferenceOptions<TValue = unknown> = {
   map?: (value: unknown) => TValue;
 };
 
-export function create(key: string, options?: ReferenceOptions) {
-  return new Reference(key, options);
+export function create<TValue = unknown>(key: string, options?: ReferenceOptions<TValue>) {
+  return new Reference<TValue>(key, options);
 }
 
 export default class Reference<TValue = unknown> {
diff --git a/src/index.ts b/src/index.ts
index 97ae53e..26f41e0 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -40,19 +40,19 @@ function addMethod(schemaType: any, name: string, fn: any) {
 type ObjectSchemaOf<T extends AnyObject> = ObjectSchema<
   {
     [k in keyof T]-?: T[k] extends Array<infer E>
-      ? ArraySchema<SchemaOf<E>>
+      ? ArraySchema<SchemaOf<E> | Lazy<SchemaOf<E>>>
       : 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<T[k]> | ObjectSchemaOf<Lazy<T[k]>>
       : BaseSchema<Maybe<T[k]>, AnyObject, T[k]>;
   }
 >;
 
 type SchemaOf<T> = T extends Array<infer E>
-    ? ArraySchema<SchemaOf<E> | Lazy<SchemaOf<E>>>
-    : T extends AnyObject
-    ? ObjectSchemaOf<T>
-    : BaseSchema<Maybe<T>, AnyObject, T>;
+  ? ArraySchema<SchemaOf<E> | Lazy<SchemaOf<E>>>
+  : T extends AnyObject
+  ? ObjectSchemaOf<T>
+  : BaseSchema<Maybe<T>, AnyObject, T>;
 
 export type AnyObjectSchema = ObjectSchema<any, any, any, any>;
 
diff --git a/src/schema.ts b/src/schema.ts
index 7ffaccd..20dfed4 100644
--- a/src/schema.ts
+++ b/src/schema.ts
@@ -137,8 +137,6 @@ export default abstract class BaseSchema<
       strict: false,
       abortEarly: true,
       recursive: true,
-      label: undefined,
-      meta: undefined,
       nullable: false,
       presence: 'optional',
       ...options?.spec,
@@ -191,7 +189,7 @@ export default abstract class BaseSchema<
   }
 
   meta(): Record<string, unknown> | undefined;
-  meta(obj: Record<string, unknown>): void;
+  meta(obj: Record<string, unknown>): this;
   meta(...args: [Record<string, unknown>?]) {
     if (args.length === 0) return this.spec.meta;
 
diff --git a/src/util/reach.ts b/src/util/reach.ts
index 504a6b5..b65c76a 100644
--- a/src/util/reach.ts
+++ b/src/util/reach.ts
@@ -2,7 +2,7 @@ import { forEach } from 'property-expr';
 
 let trim = (part: string) => part.substr(0, part.length - 1).substr(1);
 
-export function getIn(schema: any, path: string, value: any, context = value) {
+export function getIn(schema: any, path: string, value?: any, context = value) {
   let parent: any, lastPart: string, lastPartDebug: string;
 
   // root path: ''
@@ -50,7 +50,7 @@ export function getIn(schema: any, path: string, value: any, context = value) {
   return { schema, parent, parentPath: lastPart! };
 }
 
-const reach = (obj: {}, path: string, value: any, context: any) =>
+const reach = (obj: {}, path: string, value?: any, context?: any) =>
   getIn(obj, path, value, context).schema;
 
 export default reach;


Test patch:
diff --git a/test/mixed.js b/test/mixed.js
index c6551bf..01ae82a 100644
--- a/test/mixed.js
+++ b/test/mixed.js
@@ -645,6 +645,19 @@ describe('Mixed Types ', () => {
     }.should.throw(TypeError));
   });
 
+  it('concat should not overwrite label and meta with undefined', function () {
+    const testLabel = "Test Label"
+    const testMeta = {
+      testField: "test field"
+    }
+    let baseSchema = mixed().label(testLabel).meta(testMeta)
+    const otherSchema = mixed()
+
+    baseSchema = baseSchema.concat(otherSchema)
+    expect(baseSchema.spec.label).to.equal(testLabel)
+    expect(baseSchema.spec.meta.testField).to.equal(testMeta.testField)
+  })
+
   it('concat should allow mixed and other type', function () {
     let inst = mixed().default('hi');