TanStackT
TanStack5mo ago
1 reply
foolish-indigo

define server function output type / validation?

How people doing that? Usually, when designing server side I prefer to decide id advance what types should be for what endpoints and then just implement the code according to that types.

Doing it with createServerFn for now is like:
interface MyResponse  {
  id: string,
  name: string | null,
  posts: number
}

const $someServerFn = createServerFn().handler( async ({data}) => {
  // do stuff...
  const result: MyResponse = // ...
  return response
})

it is little cumbersome. Is there any place in generics where I could insert the desired output type?
Or maybe like the input validation, validation of output?
Was this page helpful?