Skip to content
Discussion options

You must be logged in to vote

Hi @alexwgraves! I'm Dosu and I’m helping the valibot team.

Valibot doesn't currently support factoring out shared properties in variant schemas via a third argument or built-in feature in v.variant—each variant option must include all its properties, so the union type repeats shared keys and can get verbose as you add more variants source.

To achieve the intersection type you want (shared properties factored out), the recommended pattern is to use v.intersect to combine your shared schema with the variant schema. This produces a type like {shared} & (variant union) and helps reduce redundancy and TypeScript complexity source.

Here's how you can do it:

const CommonSchema = v.object({
  s…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by alexwgraves
Comment options

You must be logged in to vote
1 reply
@fabian-hiller
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants