-
-
Notifications
You must be signed in to change notification settings - Fork 148
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
Custom validators #792
Comments
Yes, removed it for type safety. |
Okay, so no way to do custom comment tags anymore? The new API makes it difficult to do complicated validations because everything is a string now. For example: export type CommaSeparated<Value extends string> = tags.TagBase<{
kind: 'commaSeparated',
target: 'string',
value: Value,
validate: `$input.split(',').every(v => ${Value}.split(',').includes(v))`
}> This validator fails to compile. I want to validate if a comma separated string of values is part of a union type. Is there a better way to achieve this? Im validating a search parameter so passing an array isn't possible. |
Trying to use it like this: interface IRequestQuery {
foo: string & CommaSeparated<'bar,baz'>
} |
Ideally I would be able to use an actual union type: export type MyType = 'bar' | 'baz' |
Any suggestions on how to implement this validator? It seems to fail when I pass the iterator function to every. |
Here is a playground that demonstrates the error. It compiles ok for js but not ts. |
Succeeded to find the reason why bug being occured. Would be fixed soon, and patch version Thanks for reporting. |
Awesome! Glad to help! |
Fix #792 - custom type tag when callback function being used.
Works like a charm. Thanks! |
Hello!
Has the ability to create custom comment tags been removed from v5? It looks like the
customValidators.insert
function is no longer exported. I see the documentation for creating custom validation types, but I prefer the comment tag syntax.The text was updated successfully, but these errors were encountered: