8000 v4: Error when extending object with record · Issue #4426 · colinhacks/zod · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
v4: Error when extending object with record #4426
Closed
@mfenn

Description

@mfenn

Node v22.14.0, Zod v3.25.3

In this example I have a schema constructed by extending an object with a record.

import { z } from "zod/v4";

const foo = z.object({ a: z.string() });
const bar = z.record(z.string(), z.any());
const baz = foo.extend(bar);
baz.safeParse({ a: "a", b: "b" });

I get this runtime error on the safeParse call.

TypeError: Cannot read properties of undefined (reading 'optin')
    at file://.../node_modules/zod/dist/esm/v4/core/util.js:253:30
    at Array.filter (<anonymous>)
    at Module.optionalKeys (file:/.../node_modules/zod/dist/esm/v4/core/util.js:252:31)
    at file://.../node_modules/zod/dist/esm/v4/core/schemas.js:687:28
    at get value (file://.../node_modules/zod/dist/esm/v4/core/util.js:34:31)
    at inst._zod.parse (file://.../node_modules/zod/dist/esm/v4/core/schemas.js:781:39)
    at Module.<anonymous> (file://.../node_modules/zod/dist/esm/v4/core/parse.js:33:32)
    at inst.safeParse (file://.../node_modules/zod/dist/esm/v4/classic/schemas.js:52:46)

May be related to #4338?

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