Skip to content

Commit

Permalink
fix(core): adjust how unmapped properties assertion work
Browse files Browse the repository at this point in the history
assertUnmappedProperty now also checks for the value to be "undefined" before determining that a
property is unmapped

fix #394
  • Loading branch information
nartc committed Jan 6, 2022
1 parent b389748 commit 3f2bb0e
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions packages/core/src/lib/map/assert-unmapped-properties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,25 @@ export function assertUnmappedProperties<
destinationKey: unknown,
errorHandler: ErrorHandler
) {
const unmappedKeys = Object.keys(destination).filter((destinationKey) => {
const isAlreadyConfigured = configuredKeys.some(
(configuredKey) => configuredKey === destinationKey
);
const isWritable =
Object.getOwnPropertyDescriptor(destination, destinationKey).writable ===
true;
return !isAlreadyConfigured && isWritable;
});
const unmappedKeys = Object.entries(destination).reduce(
(result, [destinationKey, destinationValue]) => {
const isAlreadyConfigured = configuredKeys.some(
(configuredKey) => configuredKey === destinationKey
);
const isWritable =
Object.getOwnPropertyDescriptor(destination, destinationKey)
.writable === true;
if (
!isAlreadyConfigured &&
isWritable &&
destinationValue === undefined
) {
result.push(destinationKey);
}
return result;
},
[]
);

if (unmappedKeys.length) {
const parentInfo = `${sourceKey['name'] ?? sourceKey} -> ${
Expand Down

0 comments on commit 3f2bb0e

Please sign in to comment.