zod icon indicating copy to clipboard operation
zod copied to clipboard

v4: strictObject() has the same type as object()

Open lo1tuma opened this issue 7 months ago • 2 comments

I want to build a function that only accepts strictObject() schemas, but it turns out those two schemas produce the exact same type:

import * as zod from '@zod/mini';
const x = zod.strictObject({}); // const x: zod.ZodMiniObject<{}, {}>
const y = zod.object({}); //  const y: zod.ZodMiniObject<{}, {}>

I would expect to either have a dedicated type like ZodMiniStrictObject<{}, {}> or a flag like ZodMiniObject<{}, {}, 'strict'>.

lo1tuma avatar Apr 14 '25 17:04 lo1tuma

Not planned currently but I'll leave this open to gauge interest

colinhacks avatar May 15 '25 21:05 colinhacks

I’m just curios about the reasoning behind this decision. In Zod v3 this was possible.

lo1tuma avatar May 16 '25 09:05 lo1tuma

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

Issue Summary:

  • You noted that strictObject() and object() currently produce the same TypeScript type, making it impossible to distinguish strict objects by type alone.
  • You suggested adding a distinct type or flag to differentiate them.
  • @colinhacks mentioned this feature is not planned at the moment but kept the issue open to see if there was broader interest.
  • You expressed curiosity about the rationale behind this change, especially since it was possible in Zod v3.

Next Steps:

  • Please let me know if this issue is still relevant to the latest version of Zod by commenting here to keep the discussion open.
  • Otherwise, this issue will be automatically closed in 7 days.

Thanks for your understanding and contribution!

dosubot[bot] avatar Aug 15 '25 16:08 dosubot[bot]