question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Zod enums with any literals?

See original GitHub issue

Hi!

Is it possible to extend the functionality of zod enums to any literal, not just strings?

Examples of using:

z.enum([true, false, 'unknown'])
z.enum([400, 401, 404, 405, 500])

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9

github_iconTop GitHub Comments

1reaction
scotttrinhcommented, Sep 2, 2021

Per-schema error handling is definitely an issue we are already looking at (see #97), and I see that you’ve commented there already, so yeah, I’ll close this and we can track toward a better solution for the error handling there.

0reactions
dartesscommented, Sep 2, 2021

Thanks for answers!

I believe making error reporting on z.union easier to override is probably the right approach here.

Do I need to open an issue?

Do I need to close this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

v3 string only allowed for enums · Issue #338 · colinhacks/zod
See: Should be allowed to do numbers for enums. ... approach, but consider maybe separating Zod Enums (unions of literals) more distinctly ...
Read more >
Untitled
What is Zod Zod is a TypeScript-first schema declaration and validation library. I'm using the term "schema" to broadly refer to any data...
Read more >
Zod: create a schema using an existing type - Stack Overflow
@Dotan, have you found a way to do this directly with existing types or maybe another way that doesn't require using a Zod...
Read more >
zod - npm
Enums ; Intersections; Tuples; Recursive types ... Currently there is no support for Date or bigint literals in Zod.
Read more >
How to extend enums in TypeScript - LogRocket Blog
TypeScript enum best practices. We have discussed how we can extend enums in Typescript, but enums aren't a magic bullet to be used...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found