Skip to content
Discussion options

You must be logged in to vote

To solve this problem, I developed a new package called zod-compare, which provides functions for comparing Zod schemas to determine whether two schemas are equal or compatible.

import { z } from "zod";
import { isSameType, isCompatibleType } from "zod-compare";

isSameType(z.string(), z.string()); // true
isSameType(z.string(), z.number()); // false
isSameType(
  z.object({ name: z.string(), other: z.number() }),
  z.object({ name: z.string() }),
);
// false

isCompatibleType(
  z.object({ name: z.string(), other: z.number() }),
  z.object({ name: z.string() }),
);
// true

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@1mlm
Comment options

Answer selected by JacobWeisenburger
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants