[Typescript] Zod.input()

The Input is Different than the Output

We've reached the point with Zod where our input is different than our output.

In other words, you can generate types based on input as well as generating types based on the output.

For example, let's create FormInput and FormOutput types:

 
type FormInput = z.infer<typeof Form>
type FormOutput = z.infer<typeof Form>

 

Introducing z.input

As written above, the input is not quite correct because when we input into validateFormInput, we don't need to pass in any keywords.

Instead, we can update the the FormInput to use z.input instead of z.infer.

This gives us a way to slightly tweak the types we generate if there is a difference between the input and output of our validator.

posted @   Zhentiw  阅读(5)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
历史上的今天:
2022-12-21 [Typescript] 141. Extreme - Sum
2022-12-21 [React] State and Callbacks Don’t Mix Well in React
2022-12-21 [React] Valtio proxy-state management lib intro
2021-12-21 [Reac] React 18
2019-12-21 [LeetCode] 832. Flipping an Image
2019-12-21 [LeetCode] 709. To Lower Case
2019-12-21 [LeetCode] 1221. Split a String in Balanced Strings
点击右上角即可分享
微信分享提示