Confusing terms - parse vs validate #962
-
I'm still trying to wrap my head around this article that points out that parsing is superior to validating. Yet, zod coins itself as a validation library, and as far as I can judge, it is one.
Yet you have chosen to name the method to validate Would it make sense to add an alias for Otherwise, I am curious how you came to the conclusion of how to name the method :) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Thanks for your feedback here. The following thoughts are my own, but they are the reason I became involved with the Zod project, so hopefully I can provide some context here. The difference between parsing and validating in this context is that the function returns the data rather than asserting anything about the input data directly. That's the reason we don't have type guards or assertion functions, for instance. Since running the schema's checker on the value doesn't tell TypeScript anything about the input data, I feel like
That's what
We're working on improving the documentation in general, but I plan to write a more TypeScript friendly guide about this subject rather than always pointing people at Lexi's (very extremely excellent) article. In the meantime, I definitely encourage reading and re-reading the article a few times (I do so every month or so 😆) until it starts to make more sense. I'll leave this issue open for visibility while we're working on the docs and welcome any follow-up questions! |
Beta Was this translation helpful? Give feedback.
-
Thank you a lot for your kind words :) I keep reading many of the topics related to the functional programming realm, and it definitely resonates with me. |
Beta Was this translation helpful? Give feedback.
@MartinMuzatko
Thanks for your feedback here. The following thoughts are my own, but they are the reason I became involved with the Zod project, so hopefully I can provide some context here.
The difference between parsing and validating in this context is that the function returns the data rather than asserting anything about the input data directly. That's the reason we don't have type guards or assertion functions, for instance. Since running the schema's checker on the value doesn't tell TypeScript anything about the input data, I feel like
parse
is still the more semantically correct name for what Zod is doing.