You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Typescript infers the value as a string even though logging the type shows it's a number:
function MyComponent() {
const { id } = Route.useParams(); // typescript says id is a string here
console.log(typeof id); // this will print 'number'
}
Not sure if this is relevant, but if I log the output of the zodSearchValidator function I get this:
Click the Post 35 button to navigate to the posts/$postId route
Notice that it prints the type of postId as number
Hover over the postId variable in the component of the posts.$postId.tsx file and see that it infers the type as string
Expected behavior
I assume this is just a type issue since everything works as expected except the type inference. I would expect it to be type number instead of type string.
Screenshots or Videos
No response
Platform
OS: macOS
Browser: Chrome
Version: 131.0.6778.241
Additional context
No response
The text was updated successfully, but these errors were encountered:
allan-cannon
changed the title
param type validation with zod adapter does not appear to be working
type inference not working for params using type validation with zod adapter
Jan 2, 2025
At some recent update they changed what you should be doing for Zod validation adapting. If you just swap the adapter for the import in the example everything works.
Which project does this relate to?
Router
Describe the bug
When using the zodSearchValidator to validate route params, I would expect it to also coerce the typescript type, however it remains a string.
This is perhaps a regression bug because this behavior worked as expected as recently as 1.81.5 (version in repro is 1.93.0).
For example when attempting to constrain the id param to a number in this example:
Typescript infers the value as a string even though logging the type shows it's a number:
Not sure if this is relevant, but if I log the output of the zodSearchValidator function I get this:
Your Example Website or App
https://stackblitz.com/edit/github-4wp3konf?file=src%2Froutes%2Fposts.%24postId.tsx
Steps to Reproduce the Bug or Issue
Post 35
button to navigate to theposts/$postId
routenumber
postId
variable in the component of theposts.$postId.tsx
file and see that it infers the type asstring
Expected behavior
I assume this is just a type issue since everything works as expected except the type inference. I would expect it to be type
number
instead of typestring
.Screenshots or Videos
No response
Platform
Additional context
No response
The text was updated successfully, but these errors were encountered: