`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
dependent-tan•2w ago
You should just pass the schema i believe.
.validator(OrganizationSwitchSchema)
flat-fuchsia•2w ago
use
validator(SendEmailFnParams)
correct-apricotOP•2w ago
sorry not following where should I use this?
flat-fuchsia•2w ago
the way you used the schema was loosing the type information
correct-apricotOP•2w ago
oh I see, thanks a lot!