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

Question / Readme request #54

Open
pihentagy opened this issue Dec 14, 2022 · 5 comments
Open

Question / Readme request #54

pihentagy opened this issue Dec 14, 2022 · 5 comments

Comments

@pihentagy
Copy link

Hi!

Could you summarize some key differences (how to migrate, what to watch out, what is missing in myzod, which is possible in zod) if someone tries to switch from zod to myzod?

@davidmdm
Copy link
Owner

Hi, myzod's key difference is that the api is simpler and that it is more performant.

One of the key ways that it is simpler, is that it doesn't cover every Javascript type. It is solely concerned with types that you would parse from JSON or some other data format. Myzod isn't concerned with validating that an unkown type is a function or some instance of your class, or a symbol, because those values should never be unknown.

Unknown values are generally found at Network boundaries, file loading, essentially when you read and parse data from outside of your application.

Myzod, also doesn't copy values unless it deems that it needs to. Which is where the big performance difference between myzod and zod comes in. Personally I do not think zod is performant enough to run on high demand servers. Myzod is.
For browsers zod is fine since clients do not need to scale in the same way, and computers are fast.

The biggest limitation with myzod is that it is currently blocked for typescript less than 4.7
At the time of writing it, I used recursive types to express type intersections &. However in more recent versions of typescript they have changed the heuristics such that it no longer compiles.

Personally I do not have the time to try and make it compile, and do not write much typescript these days, so I am hoping that if myzod is going to be made to work with the latest typescript versions that effort will come from the community.

the TLDR:
zod is appropriate if:

  • you are on a typescript version less than 4.7
  • you need fast validation like for validating incoming requests in a server
  • prefer a smaller API

Zod has a bigger community and more APIs and tertiary tools.

@davidmdm
Copy link
Owner

Updating to say that the typescript version issue has been resolved and myzod is now compatible with latest released versions of typescript. 🎉

@tonyxiao
Copy link

tonyxiao commented Mar 4, 2023

Love the argument regarding simplicity (after all, i really don't need to validate anything that's not a JSON anyways). Good work!

@panzerchris
Copy link

panzerchris commented Mar 21, 2023

One difference I noticed between zod and myzod is that the former explicitly requires "strict: true" in your typescript compiler options. There's no mention of this in myzod documentation. Are there limitations/issues caused if you use myzod while not setting strict: true?

For an existing code base, setting strict: true can introduce a lot of code to fix if the code base didn't start off with this. In an ideal world, maybe all projects would, but I could see it being a helpful differentiator for some folks.

@davidmdm
Copy link
Owner

Yes that is a good callout. The same holds true for myzod. I will need to spend time in the readme soon.

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

No branches or pull requests

4 participants