-
Sorry if this is in the documentation but i could find it. Is it possible to set the type of output using Types from within my application i.e. if i have a Type export type Foo = {
bar: string
} How do I set that as the output type method: 'post',
input: z.object({
foo: z.string().optional(),
}),
output: z.object({}), // <----- HERE i.e. output = { data: { THIS OBJECT IS OF TYPE FOO }} Thanks in advance |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hello @MancTwonk , the concept works exactly the opposite way. In particular case: const fooSchema = z.object({
bar: z.string(),
}); then // ...
output: fooSchema, when using the {
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 |
Beta Was this translation helpful? Give feedback.
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:
then
when using the
defaultEndpointsFactory
the final positive response will be exactlyThis 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 outzod
's ecosystem f…