question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to infer mutation input type from zod validation schema

See original GitHub issue

Hi team. First of all, I’d like to say I’m really enjoying trpc, but have had some trouble integrating it on an existing project based on react-query.

If I define a mutation route with an zod input validation schema, the generated hooks mutate and mutateAsync methods have void for variables. However, replacing it with a yup schema gets me a different result.

Consider the following router:

const signupRouter = createRouter()
  .mutation('signup', {
    input: z.object({
      email: z.string().email(),
      firstName: z.string().nonempty(),
      // ....
    }),
   resolve: () => { 
     // ...
   }
  })

This is what I get when I try to use the mutation hook:

Screen Shot 2021-11-03 at 10 26 25 AM

Now, switching to yup

const signupRouter = createRouter()
  .mutation('signup', {
    input: yup.object({
      email: yup.string().email(),
      firstName: yup.string().required(),
      // ....
    }),
   resolve: () => { 
     // ...
   }
  })

This is what I get, still not optimal as there’s a weird void | T union type

Screen Shot 2021-11-03 at 10 19 02 AM

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
amantiwari1commented, Mar 5, 2022

WOW! it works after enable strict mode

thanks! @sachinraja

2reactions
sachinrajacommented, Mar 5, 2022

What’s the error @amantiwari1? You may have to enable strict mode in your tsconfig.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Generating Zod schema from TS type definitions #53 - GitHub
I'm just beginning to convert a large TS project with many types, ... convert any TS types to a zod schema and the...
Read more >
Schema validation in TypeScript with Zod - LogRocket Blog
In this article, you will learn about schema design and validation in Zod and how to run it in a TypeScript codebase at...
Read more >
TypeScript-First Schema Validation with Static Type Inference
You can define a recursive schema in Zod, but because of a limitation of TypeScript, their type can't be statically inferred. Instead you'll...
Read more >
Theo - ping.gg on Twitter: "1. What is tRPC? tRPC is a genius ...
tRPC is a genius abuse of Typescript to create a typesafe API on server and client with strong inference and validation. In plain...
Read more >
Remix Form Validation with Zod - YouTube
When your Remix application starts to grow and your forms grow in complexity, it can be easier to manage validation with a schema...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found