-
Notifications
You must be signed in to change notification settings - Fork 70
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
Generating a schema from a type with a nullable object causes an error. (v3.7.0) #203
Comments
did this work with previous versions of |
When I was using version 3.6.1, I was able to generate it without error. |
@tvillaren can you have a look please? seems like your latest changes introduced a regression. |
I am also getting this error. |
I'll have a look. |
This can be reproduced by running
output:
I see 3 separate issues:
@tvillaren do you typically use |
Yes, the use case is specific to This was introduced for Pushed a failing test to reproduce: main...tvillaren:ts-to-zod:fix-issue-203 We were missing test to cover use cases before my addition of import handling so it didn't catch it. |
We have run in to this same issues when we are generating TS Type Definitions from OpenAPI Schemas and then genarate zod-schemas from the generated TS types and interfaces. TL;DR; zod-schema generation fails with same error from this:
|
* test: adding failing test-case * test: fix test syntax * refacto: reorganise file * fix: unit test passes * clean: prettying * test: adding more test cases * doc: adding comment
Im having the same issue with: Input
Expected output
on version 3.8.3 could it need the same fix? |
@johnnyp-gg: actually export type User = {
username: string | undefined
} generates (with // Generated by ts-to-zod
import { z } from "zod";
export const userSchema = z.object({
username: z.union([z.string(), z.undefined()]),
}); which is the expected schema. |
Bug description
Error occurs and schema generation fails.
Generating a schema from a type with a nullable object causes an error. (v3.7.0)
Input
Expected output
Actual output
Versions
v5.3.3
v3.22.4
The text was updated successfully, but these errors were encountered: