#Broken server function type safety?

8 messages · Page 1 of 1 (latest)

high prism
#

I have a server function called:

const signInWithGoogle = createServerFn({ method: "POST" })
  .validator((data: unknown) =>
    z.object({ code: z.string(), state: z.string() }).parse(data)
  )
  .handler(async ({ data }) => ...);

data is typed correctly within the handler but when I call it via:

const { mutateAsync } = useMutation({
  mutationFn: signInWithGoogle,
});
await signInWithGoogle();

no errors are displayed even though the object is required.

What am I doing wrong?
Thanks

proud pumice
#

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

high prism
high prism
proud pumice
#

are you using latest zod?