Skip to content

Commit

Permalink
Annotate mask behaviour in object coercer
Browse files Browse the repository at this point in the history
  • Loading branch information
arturmuller committed Jun 30, 2024
1 parent 610ad7e commit 3c715bb
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/structs/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,15 +324,20 @@ export function object<S extends ObjectSchema>(schema?: S): any {
return value
}

const val = { ...value }
const coerced = { ...value }

// The `object` struct has special behaviour enabled by the mask flag.
// When masking, properties that are not in the schema are deleted from
// the coerced object instead of eventually failing validaiton.
if (ctx.mask && schema) {
for (const key in val) {
for (const key in coerced) {
if (schema[key] === undefined) {
delete val[key]
delete coerced[key]
}
}
}
return val

return coerced
},
})
}
Expand Down

0 comments on commit 3c715bb

Please sign in to comment.