Skip to content

Commit

Permalink
fix(classes): treat property as primitives if metaResult is null. Def…
Browse files Browse the repository at this point in the history
…ault Date to undefined if valueAtKey is undefined

fix #254
  • Loading branch information
nartc committed Feb 19, 2021
1 parent a0b39d9 commit 8e17527
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions packages/classes/src/lib/utils/instantiate.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,20 @@ export function instantiate<TModel extends Dictionary<TModel>>(
// 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<string, unknown>)[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<string, unknown>)[key] = isDefined(valueAtKey)
? new Date(valueAtKey as number)
: new Date();
: undefined;
continue;
}

Expand Down

0 comments on commit 8e17527

Please sign in to comment.