From 8e17527dc27dedfea6060a44f4bb5cbbcd62f224 Mon Sep 17 00:00:00 2001 From: Chau Tran Date: Thu, 18 Feb 2021 18:11:38 -0600 Subject: [PATCH] fix(classes): treat property as primitives if metaResult is null. Default Date to undefined if valueAtKey is undefined fix #254 --- packages/classes/src/lib/utils/instantiate.util.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/classes/src/lib/utils/instantiate.util.ts b/packages/classes/src/lib/utils/instantiate.util.ts index f166d6b01..1e330a650 100644 --- a/packages/classes/src/lib/utils/instantiate.util.ts +++ b/packages/classes/src/lib/utils/instantiate.util.ts @@ -50,19 +50,20 @@ export function instantiate>( // call the meta fn to get the metaResult of the current key const metaResult = meta(); - // if is String, Number, Boolean, assign valueAtKey or undefined - if (isPrimitiveConstructor(metaResult)) { + // if is String, Number, Boolean, Array, assign valueAtKey or undefined + // null meta means this has any type or an arbitrary object, treat as primitives + if (isPrimitiveConstructor(metaResult) || metaResult === null) { (instance as Record)[key] = isDefined(valueAtKey, true) ? valueAtKey : undefined; continue; } - // if is Date, assign a new Date value + // if is Date, assign a new Date value if valueAtKey is defined, otherwise, undefined if (isDateConstructor(metaResult)) { (instance as Record)[key] = isDefined(valueAtKey) ? new Date(valueAtKey as number) - : new Date(); + : undefined; continue; }