You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm working on a TypeScript project and need to convert a set of complex interfaces into a Zod schema for runtime validation. Here's a simplified example of the interfaces I'm working with:
My goal is to create Zod schemas for these types, especially for WithdrawParams, which involves unions and nested objects. I'm unsure how to handle the more complex parts, like:
Union types (SingleWithdrawParams and BalancedWithdrawParams)
Conditional fields (withdrawAsset and nextWithdraw)
Optional fields and nested objects (NextWithdraw)
Additionally, I have a specific requirement for the SingleWithdrawParams union:
For SingleWithdrawWithNext, I want the user to fill in only the nextWithdraw field, and not the withdrawAsset field.
For SingleWithdrawNoNext, I want the user to fill in only the withdrawAsset field, and not the nextWithdraw field.
These fields are mutually exclusive.
Could anyone provide guidance or examples of how to translate these interfaces into Zod schemas? Any advice or resources would be greatly appreciated!
Hi everyone,
I'm working on a TypeScript project and need to convert a set of complex interfaces into a Zod schema for runtime validation. Here's a simplified example of the interfaces I'm working with:
My goal is to create Zod schemas for these types, especially for
WithdrawParams
, which involves unions and nested objects. I'm unsure how to handle the more complex parts, like:SingleWithdrawParams
andBalancedWithdrawParams
)withdrawAsset
andnextWithdraw
)NextWithdraw
)Additionally, I have a specific requirement for the
SingleWithdrawParams
union:For
SingleWithdrawWithNext
, I want the user to fill in only thenextWithdraw
field, and not thewithdrawAsset
field.For
SingleWithdrawNoNext
, I want the user to fill in only thewithdrawAsset
field, and not thenextWithdraw
field.These fields are mutually exclusive.
Could anyone provide guidance or examples of how to translate these interfaces into Zod schemas? Any advice or resources would be greatly appreciated!
Thank you!
Originally posted by @alan890104 in #3885
The text was updated successfully, but these errors were encountered: