feat: added docs and test for P.object.exact(..)#244
feat: added docs and test for P.object.exact(..)#244JUSTIVE wants to merge 5 commits intogvergnaud:gitsunmin/mainfrom
Conversation
|
currently, {} could be caught by |
|
fixed {} caught by {a:P.any}, but nested object pattern should be tested |
gvergnaud
left a comment
There was a problem hiding this comment.
Thanks for contributing! A few comments
| export type ObjectExactPattern<a> = { | ||
| readonly [k in keyof a]: Pattern<a[k]>; | ||
| }; |
There was a problem hiding this comment.
Is it to force people to include any key that exist's on an object? I think that makes a lot of sense, but how does it behave when the input has type unknown and any? Could you add tests for that?
Co-authored-by: Gabriel Vergnaud <9265418+gvergnaud@users.noreply.github.com>
|
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 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: