-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Description
I love the work done here to make Zod more production ready. However, I've found a bug on enum schemas.
Reproduction
import * as z from 'zod'
import { zx } from '@traversable/zod'
const schema = z.object({
option: z.enum(['FOO', 'BAR', 'BAZ']).default('BAZ')
})
const defaultValues = zx.defaultValues(schema, { number: 0, string: '', array: [], boolean: false })
console.log(defaultValues)Expected
[Object: null prototype] { option: 'BAZ' }
Actual
[Object: null prototype] { option: { FOO: 'FOO', BAR: 'BAR', BAZ: 'BAZ' } }
Suspected bug
schema/packages/zod/src/default-value.ts
Line 209 in 4868df1
| case tagged('enum')(x): return x._zod.def.entries ?? CATCH_ALL |
Working solution
case tagged('enum')(x):
- return x._zod.def.entries ?? CATCH_ALL
+ return x._zod.def.entries
+ ? Object_values(x._zod.def.entries)[0]
+ : CATCH_ALLThis does not cover enums with default values
Metadata
Metadata
Assignees
Labels
No labels