z.coerce takes in unknowns at runtime to output Tanstack expected types zod + nextjs ssr + tanstack #1626
Unanswered
iSpeakNerd
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Tanstack form passes the data to the server as strings so I'm using z.coerce.number() to handle the conversion but the ts compiler complains about it because zod 4 reads all coerced inputs as unknowns and only outputs the correct types at runtime.
I found this https://tanstack.com/form/latest/docs/framework/react/guides/debugging#field-value-is-of-type-unknown but it's almost the inverse issue because I have
Type 'unknown' is not assignable to type 'number'.
I can
//@ts-ignore
the error but that's on the useForm({}) functio signature so I lose the safety on all other fields as well by doing that. Is there anything I can easily do to mitigate this issue?I was looking through the example and here's my setup.
zodSchema
serverValidation.ts
serverAction.ts
Beta Was this translation helpful? Give feedback.
All reactions