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

Does not handle single value unions #36

Closed
anglinb opened this issue Jul 28, 2021 · 0 comments · Fixed by #37
Closed

Does not handle single value unions #36

anglinb opened this issue Jul 28, 2021 · 0 comments · Fixed by #37

Comments

@anglinb
Copy link
Contributor

anglinb commented Jul 28, 2021

Bug description

Typescript allows for single values unions like this. It simply collapses the union so to typescript this value is really just type A = B. ts-to-zod produces a union of a single element which zod does not allow, so validation fails.

type A = 
| B

Input

type A = | B

Expected output

export const aSchema = z.literal("b");

Actual output

export const aSchema = z.union([z.literal("b")]);

Versions

  • Typescript: v4.2.3
  • Zod: v3.1.0
fabien0102 pushed a commit that referenced this issue Jul 29, 2021
* Checks in failing test documenting behavior

* Fixes test by checking for single value unions.
fabien0102 pushed a commit that referenced this issue Jul 29, 2021
* Checks in failing test documenting behavior

* Fixes test by checking for single value unions.
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 a pull request may close this issue.

1 participant