-
-
Notifications
You must be signed in to change notification settings - Fork 268
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
Updated zod to schema comparison: added mention of Schema.URL #4346
Conversation
|
@@ -221,7 +221,7 @@ S.String.pipe(S.maxLength(5)) | |||
S.String.pipe(S.minLength(5)) | |||
S.String.pipe(S.length(5)) | |||
// S.string().email() // No equivalent | |||
// S.string().url() // No equivalent | |||
S.URL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK S.URL
is not equivalent, z.string().url()
just validates a string:
import z from "zod"
console.log(typeof z.string().url().parse("https://example.com"))
// string
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Schema.Date
is also not an exact equivalent, but this fact didn't prevent it from being mentioned as an equivalent a few lines later:
schema/comparisons.md L286-L307
### Dates Zod ```ts const date = z.string().date() date.parse("2020-01-01") // pass date.parse("2020-1-1") // fail date.parse("2020-01-32") // fail ``` Schema ```ts import { Schema as S } from "effect" S.decodeUnknownSync(S.Date)("2020-01-01") // pass S.decodeUnknownSync(S.Date)("2020-1-1") // pass S.decodeUnknownSync(S.Date)("2020-01-32") // fail ```
import z from 'zod';
console.log(typeof z.string().date().parse('2020-01-01'));
// string
console.log(typeof Schema.decodeUnknownSync(Schema.Date)('2020-01-01'));
// object (Date)
And I think that's fine that they're not exactly equivalent and still mentioned because there's a value in it. When I first saw that there's no equivalent of URL validation, I was really confused, spent time reimplementing Schema.URL
, and only after I was done, I noticed it actually existed and I created absolutely the same thing.
I don't want this to happen to anybody else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it doesn't claim that they are equivalent, it shows what can be used in Schema
when the input is a string. However, without proper description, that section is confusing and should be reorganized. Furthermore, since these docs were written, some things have changed (e.g., Schema.URL
didn’t exist at the time). IMO, the entire document needs to be refactored
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assumed it claimed they were equivalent because it didn't claim otherwise. In cases where Effect had no equivalent, it was stated as:
### Times
No equivalent.
### IP addresses
No equivalent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, that's not your fault, the document needs to be restructured, it's currently confusing
Thank you @gcanti |
Type
Description
schema/comparisons.md
said that there is no alternative inEffect
tozod
'sz.string().url()
, while @KhraksMamtsov added support in #3889