question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

operations to check subset and identity of types

See original GitHub issue

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:

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:closed
  • Created 2 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
scotttrinhcommented, Aug 20, 2021

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.

0reactions
stale[bot]commented, Mar 2, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found