Skip to content

Preserve prototype-named keys in Zod maps - #3522

Open
schani wants to merge 3 commits into
masterfrom
fix/zod-prototype-record
Open

Preserve prototype-named keys in Zod maps#3522
schani wants to merge 3 commits into
masterfrom
fix/zod-prototype-record

Conversation

@schani

@schani schani commented Sep 7, 2026

Copy link
Copy Markdown
Member

z.record reconstructs decoded maps through plain-object assignment, which drops an own __proto__ key. Decode validated entry tuples with Object.fromEntries, preserving prototype-named keys, value transforms, and inferred record types.

The API test executes generated Zod code with a null-prototype input, verifies the output has an ordinary prototype and an own __proto__ descriptor, rejects Date/Map/Set inputs like z.record, and typechecks inferred numeric values. The shared JSON regression lands in downstream #3519.

Production diff: 9 additions, 1 deletion.

Validation: build; lint; API unit; TypeScript Zod fixtures 145/145.

@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown

Generated-output differences

47 files differ — 47 modified, 0 new, 0 deleted
574 changed lines — +428 / −146

Open the generated-output report →

@schani

schani commented Sep 8, 2026

Copy link
Copy Markdown
Member Author

No comments here either!

@schani

schani commented Sep 8, 2026

Copy link
Copy Markdown
Member Author

Added API tests in test/unit/typescript-zod-map-helper.test.ts. They execute generated code, preserve an own __proto__ key from a null-prototype input, verify the returned property descriptor and ordinary prototype, reject Date/Map/Set, typecheck inferred map values, and confirm the helper is absent without maps.

@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown

Generated-output differences

47 files differ — 47 modified, 0 new, 0 deleted
574 changed lines — +428 / −146

Open the generated-output report →

@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown

Generated-output differences

47 files differ — 47 modified, 0 new, 0 deleted
574 changed lines — +428 / −146

Open the generated-output report →

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

Successfully merging this pull request may close these issues.

1 participant