When transforming input using zod, the input types is inferred incorrectly. As an example, let's say our input is a string, that will be transformed to a number using zod. When we try to use this in client code, we get a type error.
// router.ts
const buildRoute = createUploadthing();
export const fileRouter = {
myUploader: buildRoute({...})
.input(z.object({ a: z.string().transform((arg) => Number(arg)) })))
.onUploadComplete(...)
};
// client.ts
const {startUpload} = useUploadThing("myUploader");
...
startUpload(files, { a: "1" }); // Gives a type error, because it wants a to be of type Number
I guess the problem is that the underlying code is using z.infer<> instead of z.input<>.
The stackblitz is not fully functional, because I could not figure out how to add zod as a dependency. I am sure it's clear what the issue is though. If you add zod as a dependency, just look at the type error when providing the input to the startUpload function.
Additional information
No response
π¨βπ§βπ¦ Contributing
[ ] πββοΈ Yes, I'd be down to file a PR fixing this bug!
Code of Conduct
[X] I agree to follow this project's Code of Conduct
Provide environment information
Describe the bug
When transforming input using zod, the input types is inferred incorrectly. As an example, let's say our input is a string, that will be transformed to a number using zod. When we try to use this in client code, we get a type error.
I guess the problem is that the underlying code is using
z.infer<>
instead ofz.input<>
.Link to reproduction
https://stackblitz.com/edit/github-ikbntz?file=src%2Fserver%2Fuploadthing.ts
To reproduce
The stackblitz is not fully functional, because I could not figure out how to add zod as a dependency. I am sure it's clear what the issue is though. If you add zod as a dependency, just look at the type error when providing the input to the
startUpload
function.Additional information
No response
π¨βπ§βπ¦ Contributing
Code of Conduct