-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Open
Labels
Description
Provide environment information
trpc 11.7.2
zod 4.1.13
Describe the bug
In the example repository, we define a schema that uses z.preprocess:
const createEntitySchema = z.object({
name: z.string(),
description: z.preprocess(
(str) => (str === '' ? null : str),
z.string().nullish()
),
});
`type CreateEntity = z.infer<typeof createEntitySchema>;` The inferred type computes to:
type CreateEntity = {
name: string;
description?: string | null | undefined;
}However when we access the mutation via TRPC's proxy wizardry, we get a type error since it thinks that description is required and of type unknown
const { mutate } = trpc.createEntity.useMutation();
const onNothing = () => {
mutate({
name: 'hello',
});
};I believe this isn't an issue when using zod v3
Link to reproduction
https://stackblitz.com/edit/github-lxakaelx?file=src%2Fpages%2Fapi%2Ftrpc%2F%5Btrpc%5D.ts
To reproduce
https://stackblitz.com/edit/github-lxakaelx?file=src%2Fpages%2Fapi%2Ftrpc%2F%5Btrpc%5D.ts
Running next build will show the type error
Additional information
No response
π¨βπ§βπ¦ Contributing
- πββοΈ Yes, I'd be down to file a PR fixing this bug!
coderabbitai