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

Add support for ZodPipeline and ZodDiscriminatedUnion #8

Merged
merged 2 commits into from
Dec 19, 2024

Conversation

KTGLeiden
Copy link
Contributor

@KTGLeiden KTGLeiden commented Dec 19, 2024

We noticed during testing that support for ZodPipeline and ZodDiscriminatedUnion was missing, something that will break if you use something like:

export const PostalCodeSchema = z
  .string()
  .transform((postalCode: string) => postalCode.toUpperCase().replaceAll(' ', ''))
  .pipe(z.string().regex(/^\d{4}(?:[A-Z]{2}|\d)?$/, 'Invalid postal code'))

Or:

export const SomeDiscriminatedUnion = z
  .discriminatedUnion('type', [
    SchemaAWithType,
    SchemaBWithType,
    SchemaCWithType,
  ])

As a DiscriminatedUnion is basically a union for the purpose of this lib I opted for the same response.
for the ZodPipeline case, I opted for the output type.

Copy link
Owner

@matejchalk matejchalk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍 Thanks for you contribution 🙂

@matejchalk matejchalk merged commit a5a9842 into matejchalk:main Dec 19, 2024
1 check passed
@matejchalk matejchalk added the enhancement New feature or request label Dec 19, 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

Successfully merging this pull request may close these issues.

3 participants