From 207aea7f333f361b3b61c6cae734ca9b53fef3d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cemalettin=20Ta=C5=9F?= Date: Sat, 12 Dec 2020 17:46:13 +0300 Subject: [PATCH] fix(schema): Don't overwrite spec values with undefined (jquense/yup#1160) --- src/schema.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/schema.ts b/src/schema.ts index 7ffaccd91..a1006abe4 100644 --- a/src/schema.ts +++ b/src/schema.ts @@ -229,7 +229,14 @@ export default abstract class BaseSchema< let base = this; let combined = schema.clone(); - const mergedSpec = { ...base.spec, ...combined.spec }; + const baseSpec = { ...base.spec }; + // only overwrite with spec values which are not undefined + const mergedSpec = Object.keys(combined.spec).reduce((accum, key) => { + if (combined.spec[key] !== undefined){ + accum[key] = combined.spec[key] + } + return accum; + }, baseSpec) // if (combined.spec.nullable === UNSET) // mergedSpec.nullable = base.spec.nullable;