You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
But VariantSchema cannot be used inside merge(). The workaround would be to have sslSchema and saslPlaintextSchema be template functions that take a schema to merge with their internals inside their implementation, but in a case of >1 level of nesting this gets ugly quickly.
Sidenote: finally valibot has a discriminated union!
The text was updated successfully, but these errors were encountered:
Yes, merge only supports object. It basically just spread its .entries into one object. This is not possible with variant.
import*asvfrom'valibot';constObjectSchema1=v.object({key1: v.string()});constObjectSchema2=v.object({key2: v.number()});// With mergeconstMergedSchema1=v.merge([ObjectSchema1,ObjectSchema2]);// With spreadconstMergedSchema2=v.object({
...ObjectSchema1.entries,
...ObjectSchema2.entries,});
There are many ways to construct such complex schemas. In some cases intersect may be a better option than merge. Read more here: https://valibot.dev/guides/intersections/
I have a seemingly simple use-case where I'd like to do this:
But VariantSchema cannot be used inside merge(). The workaround would be to have
sslSchema
andsaslPlaintextSchema
be template functions that take a schema to merge with their internals inside their implementation, but in a case of >1 level of nesting this gets ugly quickly.Sidenote: finally valibot has a discriminated union!
The text was updated successfully, but these errors were encountered: