computed properties in zod

my api returns an object with dates as the key - is this possible to model in zod?
const response = {
"2023-11-10": <value>,
"2023-11-11": <value>
}
const response = {
"2023-11-10": <value>,
"2023-11-11": <value>
}
something like:
const schema = z.object({
[z.string()]: <value>
})
const schema = z.object({
[z.string()]: <value>
})
2 Replies
teos
teos12mo ago
Yes you can use z.record(keyType, valueType) (https://zod.dev/?id=record-key-type)
z.record(z.string().min(1), z.number())
GitHub
TypeScript-first schema validation with static type inference
TypeScript-first schema validation with static type inference
char
char12mo ago
thank you so much!
Want results from more Discord servers?
Add your server