Closed TheYarin closed 1 year ago
Good idea, I will try your solution
I tried your solution, but it was hard for me to syncing the custom validation logic, because typia
constructs validation logic in the compilation level, and can't sure which file (validation code vs custom validation logic insertion code) would be compiled earlier.
Therefore, studying your suggestion, I've decided how to support the custom validation function.
I'll write the new solution as a new article. Thanks for suggestion.
Feature Request
The problem I'm trying to solve:
email
,ipv6
,@length
,@minimum
,@pattern
etc. There is still a need for truely custom validation.The suggested solution:
Allow registering custom validation functions for a given type
The custom validation function will be executed after typia's generic type validation succeeds
To validate type
T
, The function's signature will be(t: T) => boolean
After registration, any attempt to validate type
T
will go through the custom validation as wellRemaining open questions:
How will the registration look like?
registerCustomValidator<T>(validator: (t: T) => boolean);
that users will call right after the type definition?In case of the custom validation failing, how should an error message be delivered to the user, if at all?
Example: