Z
Zod•4mo ago
angrybacon

angrybacon - Hello 👋 apologies in advance if I...

Hello 👋 apologies in advance if I missed it in the issues or documentation Are named tuple members a thing in Zod?
type Range = [left: number, right: number];
type Range = [left: number, right: number];
Solution:
https://zod.dev/?id=tuples I'm guessing to add names, you might need to pass a generic type to z.tuple. Alternatively you could use a refine, something like this (haven't checked the syntax, so could be slightly off): ```ts...
GitHub
TypeScript-first schema validation with static type inference
TypeScript-first schema validation with static type inference
Jump to solution
2 Replies
Solution
Svish
Svish•4mo ago
https://zod.dev/?id=tuples I'm guessing to add names, you might need to pass a generic type to z.tuple. Alternatively you could use a refine, something like this (haven't checked the syntax, so could be slightly off):
z.tuple([ z.number(), z.number() ])
.refine((_): _ is [left: number, right: number]
=> true)
z.tuple([ z.number(), z.number() ])
.refine((_): _ is [left: number, right: number]
=> true)
GitHub
TypeScript-first schema validation with static type inference
TypeScript-first schema validation with static type inference
angrybacon
angrybaconOP•4mo ago
That seems pretty verbose but can't think of any other way, thanks I'll try it out
Want results from more Discord servers?
Add your server