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

Fix handling of schemas with .transform in them #32

Merged
merged 4 commits into from
Dec 27, 2024

Conversation

netroy
Copy link
Contributor

@netroy netroy commented Dec 27, 2024

Fixes #31

test/zod-class.test.ts Outdated Show resolved Hide resolved
This was referenced Dec 27, 2024
@despairblue
Copy link
Contributor

I added some suggestions here: netroy#1

? z.output<T>
: never;

export type input<T> = T extends new (...args: any[]) => infer R
Copy link
Owner

Choose a reason for hiding this comment

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

Curious, what was the reason to separate out into input/output?

Copy link
Contributor

Choose a reason for hiding this comment

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

The constructors argument should be of the type z.input<schema> and the instance type of the class should be z.output<schema> with z.input being the type of what should go into z.parse and z.output is the type it returns if parsed successfully which includes all transforms which can change the type.

I could try to parameterize this type and have z.input and z.output passed in as a type parameter to reduce the duplication. Should I give that a try?

I hope I got the question right, if not let me know :)

@sam-goodwin sam-goodwin merged commit 4dd7127 into sam-goodwin:main Dec 27, 2024
1 check passed
@sam-goodwin
Copy link
Owner

Thanks @netroy and @despairblue, the fix is released in 0.0.16

@netroy netroy deleted the fix-31-handle-transform-schemas branch December 27, 2024 21:11
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

Successfully merging this pull request may close these issues.

Problem with parse method when zod.transform is used in a schema
3 participants