Skip to content

using types from my project as output type #972

Answered by RobinTail
MancTwonk asked this question in Q&A
Discussion options

You must be logged in to vote

Hello @MancTwonk ,

the concept works exactly the opposite way.
You declare schemas using zod schemas and then you can convert those schemas to Typescript types for your application (see Client generation in the docs).

In particular case:

const fooSchema = z.object({
  bar: z.string(),
});

then

// ...
output: fooSchema,

when using the defaultEndpointsFactory the final positive response will be exactly

{ 
  status: "success",
  data: { 
    foo: { 
      bar: string 
    } 
  } 
}

This way types can be declared more precise and contain additional features, like refinements and transformations.

However, if you still need to convert Typescript types to zod schemas, check out zod's ecosystem f…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by RobinTail
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
good first issue Good for newcomers
2 participants