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

discriminator cannot be used when --export-type being applied #216

Open
PeterMK85 opened this issue Aug 22, 2023 · 0 comments
Open

discriminator cannot be used when --export-type being applied #216

PeterMK85 opened this issue Aug 22, 2023 · 0 comments

Comments

@PeterMK85
Copy link
Contributor

PeterMK85 commented Aug 22, 2023

Describe the bug
If the export-type being used and the schema is referencing another schema with the z.ZodType declaration, zod's z.discriminatedUnion wont' work.

Minimal reproduction
Example

Check the metric field on Pet

Expected behavior

const MoneyMetric: z.ZodType<MoneyMetric> = z.object({
    id: z.string(),
    name: z.string(),
    value: z.number(),
    type: z.literal('MONEY'),
    details: z.object({ currency: z.string().min(3).max(3) }),
})

const Metric = z.discriminatedUnion('type', [MoneyMetric, NumberMetric])

Should not throw an error, however I think the root of the issue us that ZodType does not work with the discriminatedUnion

Additional context
I think this reveals an under laying issue. const MoneyMetric: z.ZodType<MoneyMetric> = approach works nicely to eliminate the TS7056 error, but on the other hand the schemas which has the ZodType type casting no longer "real" Zod schemas, they cannot be merge/extend and it seems these cannot be part of the discriminatedUnion declaration

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant