-
-
Notifications
You must be signed in to change notification settings - Fork 138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: added docs and test for P.object.exact(..) #244
base: gitsunmin/main
Are you sure you want to change the base?
Conversation
currently, {} could be caught by |
fixed {} caught by {a:P.any}, but nested object pattern should be tested |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 <[email protected]>
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: