[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.
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源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