How can I perform discriminated union validations with Elysia’s built-in validator? #1048
Unanswered
Mateusvaz89
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
I’m currently working with Elysia and trying to implement a validation similar to the following discriminated union example using Zod:
const schema = z.discriminatedUnion("paymentMethod", [
z.object({
paymentMethod: z.literal("creditCard"),
card: z.object({
number: z.string(),
holderName: z.string(),
expirationDate: z.string(),
securityCode: z.string(),
}),
}),
z.object({
paymentMethod: z.literal("coupon"),
couponCode: z.string(),
}),
]);
My goal is to achieve the same type of validation using Elysia’s default validator. However, I’m unsure how to translate this discriminated union logic into the built-in validation system provided by Elysia.
Could someone please guide me on how to implement this? Any examples or documentation pointers would be greatly appreciated.
Thank you in advance!
Beta Was this translation helpful? Give feedback.
All reactions