8000 v4: Records cannot have `z.number` keys · Issue #4383 · colinhacks/zod · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

v4: Records cannot have z.number keys #4383

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
LorisSigrist opened this issue May 16, 2025 · 1 comment
Closed

v4: Records cannot have z.number keys #4383

LorisSigrist opened this issue May 16, 2025 · 1 comment

Comments

@LorisSigrist
Copy link
Contributor

The v4 documentation for z.record states that "The key schema can be any Zod schema that is assignable to string | number | symbol"

In practice z.number and z.coerce.number cannot be used as keys

The following fails because the key gets stringified to '1'.

z.record(z.number(), z.number()).parse({ 1: 1 })

Using z.coerce.number works, but causes a type-error. ZodCoercedNumber is not assignable to $ZodRecordKey.

z.record(z.coerce.number(), z.number()).parse({ 1: 1 })

What is the intended behavior here?

(tested on 3.25.0-beta.20250515T085033)

@colinhacks
Copy link
Owner

This is addressed at the bottom of the "Records" section. TLDR don't do it 🤷‍♂️

Image

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

2 participants
0