#Can i import types from query-outputs like trpc's RouterOutputs.

3 messages · Page 1 of 1 (latest)

visual bay
#

👆 ( in frontend components to have typesafety passing props). I know i can get the type of schema models.

molten vineBOT
#

Hi @visual bay. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Yes, you can import types from query outputs in Convex. However, the exact method may vary depending on the specific setup of your project. For instance, in a tRPC project, you can provide a Zod object to .input to validate your endpoint’s arguments. Here's an example:

const t = initTRPC.create();
 
const appRouter = t.router({
  greeting: t.publicProcedure
    .input(z.object({ name: z.string() }))
    .query((opts) => {
      const { input } = opts;
      return `Hello ${input.name}`;
  }),
});

In this example, the type of input is inferred from the Zod schema provided to .input.

For more specific guidance on importing types in Convex, you may want to refer to the Convex documentation (https://docs.convex.dev/) or ask in the Convex community channels.

Source (https://stack.convex.dev/typescript-zod-function-validation#using-zod-for-argument-validation-server-side)

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: