Skip to content
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

Return an union type in Validation functions #19

Closed
wants to merge 2 commits into from

Conversation

vtrofin
Copy link

@vtrofin vtrofin commented Aug 10, 2022

The issue

Our custom validation function need to be able to return custom error messages in case the input value is invalid.

The fix

In order to return custom error messages, we need to enable our custom validation function to return either a boolean or a string instead of a falsy value. I've created a new union type and i've updated the Example in this repository with a couple of validation functions, one of which will return a custom error message string.

Screen Shot 2022-08-10 at 14 21 00

Screen Shot 2022-08-10 at 14 20 52

@vtrofin vtrofin requested a review from haoScoville August 10, 2022 05:27
@vtrofin vtrofin self-assigned this Aug 10, 2022
@@ -0,0 +1,5 @@
@unboxed type rec t = Any('value): t

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't seem to understand this line. Can you explain it in more details? And why should we wrap the handler with Any?

Copy link

@haoScoville haoScoville left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything looks fine, I'll approve this PR and take some time to read about Union type in Rescript. Thank you @vtrofin

@vtrofin
Copy link
Author

vtrofin commented Aug 10, 2022

Closing the pr without merging because i found there is some custom implementation in Ats-client without returning different types from the validation function. See here where we map the error type into a custom error message. Having in mind we're moving away from ReScript i'll go with the existing error mapping rather than add another level of complexity with an union type return on validation functions.

@vtrofin vtrofin closed this Aug 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants