`createServerFn` Zod validation works, but TS doesn’t catch invalid params at callsite?
I'm using createServerFn from
@tanstack/react-start with Zod validation to define sendEmailFn. Everything works at runtime (thanks to .validator(...)), but TypeScript doesn't enforce the parameter shape when calling sendEmailFn()—I can omit fields or add invalid ones, and TS doesn’t complain. Only Zod throws at runtime. Why isn't TypeScript checking the input types at compile-time?
Example code
I can call it with whatever params I want, what am I missing 🤔
5 Replies
fair-rose•4mo ago
You should just pass the schema i believe.
.validator(OrganizationSwitchSchema)
rising-crimson•4mo ago
use
validator(SendEmailFnParams)adverse-sapphireOP•4mo ago
sorry not following where should I use this?
rising-crimson•4mo ago
the way you used the schema was loosing the type information
adverse-sapphireOP•4mo ago
oh I see, thanks a lot!