-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
operations to check subset and identity of types #598
Comments
That's a fun one! I could see something like an |
I think // Runtime equivalent of `Main extends A`
main.extends(a) // true
main.extends(b) // false
main.extends(c) // false |
There's already an |
That's fair, but also true of TypeScript itself, and has some nice symmetry. I definitely get that the symmetry is also potentially confusing. Maybe My only small qualm with using superset/subset in this context, is that it's a potentially confusing term when not dealing with |
Maybe doesExtend to make it clear that it's a predicate? It'd be nice to
stick to something close to the compile-time language since we attempt to
do that elsewhere.
Agreed!
I started digging through the code to see how hard basic type equality is.
For most non collection types it's fairly simple, but both z.string and
z.number offer a bunch of checkers that need some work to make them
comparable. I haven't looked too deeply into the rest yet.
… |
Oh, that's a good point: if we want it to return |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
I find myself with the use case to check whether a Zod type is a subset of another Zod type, and also, to help implement it, whether a Zod type is identical to another Zod type. I saw in the code earlier versions of Zod had an
.is
operation that has been removed.So given:
Then:
This might get hairy with intersection types, though I'm not particularly concerned with this right now. Is anyone working on anything like this or is there a solution already?
The text was updated successfully, but these errors were encountered: