fabian-hiller / valibot

The modular and type safe schema library for validating structural data 🤖
https://valibot.dev
MIT License
6.32k stars 204 forks source link

getDefault() doesn't work with object schemas? #884

Closed laneme closed 1 month ago

laneme commented 1 month ago
 const OptionalStringSchema = v.object({
    cake: v.optional(v.string(), "Chocolate!"),
 })
 const defaultValue = v.getDefault(OptionalStringSchema)
 console.info(defaultValue) // undefined

Its even typed undefined. Is this something not implemented yet?

It works with the primitives tho

v.getDefault(OptionalStringSchema.entries.cake) // Chocolate

Versions

"valibot": "^0.42.1",
"typescript": "~5.6.3",
fabian-hiller commented 1 month ago

Please have a look at getDefaults: https://valibot.dev/api/getDefaults/

laneme commented 1 month ago

Silly me just ignoring the letter s. Ty ^^