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

Schema for picked and nullabled type is not nullable #129

Open
t-animal opened this issue May 8, 2023 · 2 comments
Open

Schema for picked and nullabled type is not nullable #129

t-animal opened this issue May 8, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@t-animal
Copy link

t-animal commented May 8, 2023

Bug description

When picking a subtype and marking it nullable, the generated zod schema loses the nullable attribute

Input

export type foo = {
        bar: number;
}

export type bla = foo['bar'] | null

Expected output

export const blaSchema = fooSchema.shape.bar.nullable();

Actual output

export const blaSchema = fooSchema.shape.bar

Versions

  • Typescript: 4.9.3
  • Zod: 3.21.4
@fabien0102
Copy link
Owner

Hey, I guess you did a mistake writing the issue since the "Expected output" and "Actual output" are identical.

But running it locally, I can see than the actual output is the following:

export const fooSchema = z.object({
  bar: z.number(),
});

export const blaSchema = fooSchema.shape.bar;

Good catch!

@t-animal
Copy link
Author

Yes, sorry. I have updated the issue.

@tvillaren tvillaren added the bug Something isn't working label Mar 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants