operations to check subset and identity of types
See original GitHub issueI 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:
const main = z.object({foo: z.string(), bar: z.string()});
const a = z.object({foo: z.string()});
const b = z.object({foo: z.number()});
const c = z.object({other: z.string()});
Then:
a.isSubset(main) // true, as foo is in main and the same type
b.isSubset(main) // false, as foo is not the same
c.isSubset(main) // false, as other is not present in main
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?
Issue Analytics
- State:
- Created 2 years ago
- Comments:7
Top Results From Across the Web
Set Identities (Defined & Illustrated w/ 13+ Examples!)
Set identities are the properties and laws of sets that help us demonstrate and prove set operations, subsets and equivalence.
Read more >Set Identities - Math24.net
We now consider the basic set identities that relate the various set operations. The sets A, B, C below are subsets of a...
Read more >5.1: Sets and Operations on Sets - Mathematics LibreTexts
Let A and B be two sets contained in some universal set U. The set A is a proper subset of B provided...
Read more >List of set identities and relations - Wikipedia
This article lists mathematical properties and laws of sets, involving the set-theoretic operations of union, intersection, ... Several of these identities or "laws"...
Read more >Sets and Set Operations - University at Buffalo
We write A ⊆ B if A is a subset of B. Clearly, for any set A, the empty set ∅ (which does...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
That’s a fun one! I could see something like an
extends
method that works like a conditional type. Nothing built in that I’m aware of, but would be happy to help point you in the right direction or review a PR to add it.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.