Broken server function type safety?
I have a server function called:
data
is typed correctly within the handler but when I call it via:
no errors are displayed even though the object is required.
What am I doing wrong?
Thanks5 Replies
sunny-green•9mo ago
data is unknown as the input type
it would need to be typed differently to get a type error here
to avoid this, just supply the zod schema as validator without wrapping it
rare-sapphireOP•9mo ago
If you mean
.validator(z.object({ code: z.string(), state: z.string() }))
then that yields the same result
Why is that? And if so, why is it typed correctly within the handler
?sunny-green•9mo ago
are you using latest zod?
sunny-green•9mo ago
that's the relevant section
https://tanstack.com/router/latest/docs/framework/react/start/server-functions#inference
Server Functions | TanStack Router React Docs
What are Server Functions? Server functions allow you to specify logic that can be invoked almost anywhere (even the client), but run only on the server. In fact, they are not so different from an API...
rare-sapphireOP•9mo ago
Upgrading from 3.23 to 3.24.1 solved the issue. Thanks 👍