8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
z.number
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
The v4 documentation for z.record states that "The key schema can be any Zod schema that is assignable to string | number | symbol"
z.record
string | number | symbol
In practice z.number and z.coerce.number cannot be used as keys
z.coerce.number
The following fails because the key gets stringified to '1'.
'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.
ZodCoercedNumber
$ZodRecordKey
z.record(z.coerce.number(), z.number()).parse({ 1: 1 })
What is the intended behavior here?
(tested on 3.25.0-beta.20250515T085033)
3.25.0-beta.20250515T085033
The text was updated successfully, but these errors were encountered:
This is addressed at the bottom of the "Records" section. TLDR don't do it 🤷♂️
Sorry, something went wrong.
No branches or pull requests
The v4 documentation for
z.record
states that "The key schema can be any Zod schema that is assignable tostring | number | symbol
"In practice
z.number
andz.coerce.number
cannot be used as keysThe following fails because the key gets stringified to
'1'
.Using
z.coerce.number
works, but causes a type-error.ZodCoercedNumber
is not assignable to$ZodRecordKey
.What is the intended behavior here?
(tested on
3.25.0-beta.20250515T085033
)The text was updated successfully, but these errors were encountered: