We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
When an optional property references a union type with null, the result is not using the optional() modifier
null
optional()
export interface A { a?: number | null; }
export const aSchema = z.object({ a: z.number().optional().nullable() });
export const aSchema = z.object({ a: z.number().nullable() });
Did some fiddling on a fork, and found that the isOptional flag was not passed down in case of an union type traversal.
isOptional
Versions
v4.5.2
v1.7.0
The text was updated successfully, but these errors were encountered:
Actually, my PR doesn't fix all cases, only the "simple" one.
Union with multiple primitive types and null fails as well:
it("should allow nullable on union properties", () => { const source = `export interface A { a: number | string | null; } `; expect(generate(source)).toMatchInlineSnapshot(` "export const aSchema = z.object({ a: z.union([z.number(), z.string()]).nullable() });" `); });
I proposed a fix in my PR as well.
Sorry, something went wrong.
Part of 1.8.0 release 😀
1.8.0
Successfully merging a pull request may close this issue.
Bug description
When an optional property references a union type with
null
, the result is not using theoptional()
modifierInput
Expected output
Actual output
Potential fix
Did some fiddling on a fork, and found that the
isOptional
flag was not passed down in case of an union type traversal.Versions
v4.5.2
v1.7.0
The text was updated successfully, but these errors were encountered: