Using custom
with a predefined schema?
#508
-
Hello! I'm exploring a migration from Zod to Valibot and stuck on what I assume is a simple issue. In Zod, I can take a schema,
Thank you for your help! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
This is already possible, but I am aware that it is a bit cumbersome. That's why we're currently changing that part of the API in #502.
import * as v from 'valibot';
const FooSchema = v.object({ foo: v.string([v.toTrimmed(), v.email()]) });
const ExtendedFoo = v.object(FooSchema.entries, [
v.custom(({ foo }) => foo.includes('@gmail'), 'Error: Not a Gmail!')
]); |
Beta Was this translation helpful? Give feedback.
-
This is great! The current syntax isn’t terrible but the new syntax is quite exciting and will be a very significant improvement. Thank you so much for the quick reply and all your work! |
Beta Was this translation helpful? Give feedback.
This is already possible, but I am aware that it is a bit cumbersome. That's why we're currently changing that part of the API in #502.