zod icon indicating copy to clipboard operation
zod copied to clipboard

possible bug: standard schema introduction v3.24 breaks libraries that depend on core zod exposed types

Open malkhuzayyim opened this issue 8 months ago • 3 comments

Hi, long time zod user, love the work thank you all to who contribute.

Issue Brief

I think the introductiion of the ~standard and ~validate props has broken how some libraries wrap zod functionality and extend it

I was trying out the hono middleware mentioned by cloudflare's official docs: https://github.com/honojs/middleware/tree/main/packages/zod-validator

And it no longer works due to v3.24 i believe.

The error message if you follow the exact example they mention today is:

Argument of type 'ZodObject<{ message: ZodString; }, "strip", ZodTypeAny, { message: string; }, { message: string; }>' is not assignable to parameter of type 'ZodType<any, ZodTypeDef, any>'.
  Type 'ZodObject<{ message: ZodString; }, "strip", ZodTypeAny, { message: string; }, { message: string; }>' is missing the following properties from type 'ZodType<any, ZodTypeDef, any>': "~standard", "~validate"ts(2345)

Internal Implementation of hono's zod validator can be seen here: https://github.com/honojs/middleware/blob/main/packages/zod-validator/src/index.ts

And the return type of the user's const schema = z.object({ ... }) is no longer a match

Possible Solution

Two options to patch this come to mind:

  1. return types when making schema's with z.object should also have those props "~standard" & "~validator"
  2. or make them optional on the core types until the next major release?

Thanks again, I hope this is useful.

malkhuzayyim avatar Mar 28 '25 09:03 malkhuzayyim

I can confirm that pinning the Zod package to v3.23.8 via overrides in package.json using pnpm eliminates the error, like so:

"pnpm": {
    "overrides": {
      "zod": "3.23.8"
    }
  }

malkhuzayyim avatar Mar 28 '25 09:03 malkhuzayyim

Same here. We are now getting type errors on v3.24.x (I've tried up to latest 3.24.2).

missing the following properties from type 'ZodType<any, any, any>': "~standard", "~validate", openapi

openapi is coming from zod-openapi but I'm assuming it's a similar issue. Perhaps there needs to be a fix in upstream packages as well.

Like @malkhuzayyim mentioned, it's working on v3.23.8 and prior.

rt-joe avatar Apr 02 '25 16:04 rt-joe

I just updated to v3.24.3 and it's working again 🤷

rt-joe avatar Apr 22 '25 16:04 rt-joe

Assignability issues are complicated. This is usually due to multiple versions of Zod existing simultaneously in your codebase. @dosu chime in.

colinhacks avatar Jun 16 '25 23:06 colinhacks

Hi, @malkhuzayyim. I'm Dosu, and I'm helping the Zod team manage their backlog and am marking this issue as stale.

Issue Summary:

  • You reported that Zod v3.24 introduced ~standard and ~validate properties causing type errors with libraries like hono's zod-validator.
  • Other users confirmed the issue and found pinning to v3.23.8 resolved the errors temporarily.
  • Maintainer @colinhacks noted that multiple Zod versions in a project often cause such assignability issues.
  • Later, v3.24.3 was confirmed to work again, indicating the problem was addressed.

Next Steps:

  • Please confirm if this issue is still relevant with the latest Zod version.
  • If it is, feel free to comment to keep the discussion open; otherwise, I will close this issue automatically in 7 days.

Thanks for your understanding and contribution!

dosubot[bot] avatar Oct 08 '25 16:10 dosubot[bot]