Unable to infer mutation input type from zod validation schema
See original GitHub issueHi 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:
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
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (5 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
WOW! it works after enable strict mode
thanks! @sachinraja
What’s the error @amantiwari1? You may have to enable strict mode in your tsconfig.