Open JUSTIVE opened 7 months ago
currently, {} could be caught by P.object.exact({a: P.any})
pattern.
fixed {} caught by {a:P.any}, but nested object pattern should be tested
during the implementation of this feature, I'm concerned about the following scenarios.
maybe we need to consider those cases first before implementing it.
I was think that exact({ ... })
would only apply to the current level of nesting. If you want everything to be exact, then you need to nest exact
s as well:
P.object.exact({
// this object should only have a single `a` key
a: {
// this object must have at least a `b` key that's a string.
b: P.string
}
})
If you want everything to be exact you'd do:
P.object.exact({
a: P.object.exact({
b: P.string
})
})
Do you find a problem with that? What are the scenarios that worry you?
I think that behavior could easily cause misunderstanding. I thought exact should catch 'exact' object matching, not 'exact matching, but only single depth'. It's a bit ambiguous.
I'll keep implementing with single-depth match version(because it's a sub-spec of full-depth matching), but still not sure it's good design or not.
adds docs, and tests for P.object.exact
Todos: