Skip to content
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

Possible to use zod effects inside union elements? #7

Open
phoneticallySAARTHaK opened this issue Jan 31, 2024 · 0 comments
Open

Possible to use zod effects inside union elements? #7

phoneticallySAARTHaK opened this issue Jan 31, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@phoneticallySAARTHaK
Copy link

I'm trying to use .refine on a discriminated union element, but it's probably not possible.

const GetRegionRequestSchema = y.discriminatedUnion('type', [
	z.object({ type: z.literal('COUNTRY') }),
	z.object({
		type: z.literal('STATE'),
		country_id: z.string().optional(),
		coutry_name: z.string().optional(),
	}).refine((val) => !val.coutry_name && !val.country_id ? false : val),
	z.object({
	type: z.literal('CITY'),
	state_id: z.string(),
	})
])

I can do refine on the discriminatedUnion itself, but just wanted to know if this usecase is possible

@phoneticallySAARTHaK phoneticallySAARTHaK added the enhancement New feature or request label Jan 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant