v4: strictObject() has the same type as object()
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'>.
Not planned currently but I'll leave this open to gauge interest
I’m just curios about the reasoning behind this decision. In Zod v3 this was possible.
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()andobject()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!