8000 @zod/mini: extend and merge return plain object · Issue #4154 · colinhacks/zod · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

@zod/mini: extend and merge return plain object #4154

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
aliechti opened this issue Apr 15, 2025 · 2 comments
Closed

@zod/mini: extend and merge return plain object #4154

aliechti opened this issue Apr 15, 2025 · 2 comments

Comments

@aliechti
Copy link

In @zod/mini, both extend and merge lose schema type information and resolve to a plain object, breaking inference.

import * as z from "@zod/mini";

const Test = z.object({
  test: z.string(),
});

const Test2 = z.extend(Test, {
  test2: z.string(),
});

type Test2 = z.infer<typeof Test2>;

const test2 = {} as Test2;

console.log(test2.test);
console.log(test2.test2);

Errors:

Property 'test' does not exist on type 'object'.
Property 'test2' does not exist on type 'object'.

Playground Link

Workaround

Using .intersection() works but is not compatible with ZodMiniObject and introduces other type issues.

Expected

extend and merge should preserve the schema and allow proper type inference like in zod.

@dartess
Copy link
dartess commented Apr 23, 2025

looks like a duplicate of #4082

@colinhacks
Copy link
Owner

Fixed some time ago, upgrade to the latest betas. 👍


Note that you'll need to rewrite your v4 imports to "zod/v4" after upgrading; for more information, see #4364

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
0