-
-
Notifications
You must be signed in to change notification settings - Fork 616
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
check: support default options for validationResult #474
check: support default options for validationResult #474
Conversation
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.
This is perfect - thanks!!
Exactly how I would approach that issue.
I left some comments regarding minor things though.
Can you please fix them?
README.md
Outdated
@@ -367,6 +367,28 @@ try { | |||
} | |||
``` | |||
|
|||
### `.withDefaults(options)` | |||
- `options` *(optional)*: an object of options. Defaults to `{ formatter: error => error }` | |||
> *Returns:* a new validation result instance with provided default options |
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.
Saying "a new validation result instance" could be misleading.
What do you think of rewriting it to say that a new validationResult
function is returned, using the provided options? Will also be great to link to that function's section in the docs!
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.
Makes perfect sense to me
check/type-definition.spec.ts
Outdated
@@ -23,6 +24,15 @@ result.formatWith(error => { | |||
error.value; | |||
}); | |||
|
|||
withDefaults({ |
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.
Can you use validationResult.withDefaults()
? So that it matches the documented example.
I think this will also require changes to how the type declaration is done...
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.
It will also be worth changing the test to const result: ValidationResult = validationResult.withDefaults(...)(req)
.
Should catch all possible typing bugs...
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.
I think it should be set now.
I kept validationResult
interface as lower-camel-cased, since it might be more easily identifiable as a function. If any objections, I can also change to ValidationResult
.
Thanks for the feedback and absolutely! I'm working on addressing your requested changes 👍 |
Hello @gustavohenke - comments addressed. Let me know if anything else needs a tweak. |
de770e2
to
8c6245e
Compare
Thanks again! |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
This is a proposal to resolve #427, by introducing a way to set default options for the
validation-result
moduleIt introduces a new
.withDefaults
function, which will return a new instance of the module with specified default options. The decision to return a new instance was to avoid affecting the global module state in the case that multiplevalidationResult
implementations are desired within the same application.This is loosely inspired on the concept of
request.defaults
from the request/request moduleHere's a brief example:
Note: This is my first time getting acquainted with TypeScript, so let me know if the definitions make sense