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
Closed
@aliechti

Description

@aliechti

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0