Support Zod's "parseAsync" method
See original GitHub issueI’ve added an async transform to as Zod validator - and looks like tRPC does not support that.
Whan I use:
z.string().nullable().transform(async (base64string) => { return await uploadToCloud(base64string).id; })
I get: “TRPCClientError: Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.”
Any solution?
This is very important for situations like uploading files to external services.
Thanks!
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
colinhacks/zod: TypeScript-first schema validation ... - GitHub
Zod is a TypeScript-first schema declaration and validation library. I'm using the term "schema" to broadly refer to any data type, from a...
Read more >Schema Validation with Zod and Express.js
const validate = (schema: AnyZodObject) => async (req: Request, res: Response, next: NextFunction) => { try { await schema.parseAsync({ body: ...
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
parseAsync method to parse data! Otherwise Zod will throw an error. Relationship to transforms. Transforms and refinements can be interleaved: z.string() .
Read more >/README.md | zod@v3-snapshot-2021-01-21 | Deno
parseAsync method to parse data! Otherwise Zod will throw an error. As you can see, .refine takes two arguments. The first is the...
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
Let me know if you need any further guidance on how to navigate the codebase when adding the
parseAsync
, @danielyogel. It should just be a matter of turning some functions async.No, this feature is already supported by Zod using “transform” / “transformAsync”. I mean, that the result of the validation (+ transform), can be “encoded” back into a different type that is still defined in the same schema. This can be used for example, for “encoding” back data that the tRPC’s resolver returns, using the same shema. Maybe io-ts explains this better than me: io-ts. Note that io-ts support this, but does not support async encoders/decoders 😦
I guess it is more related to Zod than tRPC for now - and I saw more people ask for this in Zod’s repo.