zod icon indicating copy to clipboard operation
zod copied to clipboard

ZodRecord.create ZodType checking issue

Open keller-mark opened this issue 2 years ago • 0 comments

Hi, I have a use case in which I use Zod internally in my JS library, but I also want users to be able to use Zod to define plugins for the library (defined externally to my NPM package).

I have run into an issue where ZodRecord.create() results in unexpected behavior due to this if statement:

https://github.com/colinhacks/zod/blob/28c19273658b164c53c149785fa7a8187c428ad4/src/types.ts#L3409

The instanceof ZodType check fails due to having two independent "copies" of Zod: the one internal to my JS library, and one in userland. The user then ends up with z.record(z.string(), first) but they expected z.record(first, second).

Observable notebook with minimal reproducer: https://observablehq.com/d/25a9954667141376

Perhaps there is a better way to check for the second parameter being a Zod schema that would work across multiple independent copies of Zod imports.

keller-mark avatar Sep 17 '23 14:09 keller-mark