Optional Input and Required Output #1283
Replies: 1 comment 4 replies
|
Hi @samstorment! I'm Dosu and I’m helping the valibot team. You don't need to use both const schema = v.object({
sort: v.optional(v.string(), 'desc'),
});
type Input = v.InferInput<typeof schema>; // { sort?: string | undefined }
type Output = v.InferOutput<typeof schema>; // { sort: string }This is the recommended and concise approach— Use To reply, just mention @dosu. Docs are dead. Just use Dosu. |
Uh oh!
There was an error while loading. Please reload this page.
I've found a way to create a schema with optional input and required output types using default values with
optionalandfallback. However, it's pretty clunky because I have to pass my default value to both of those functions. Is there a better way to do what I'm trying below so I don't have to pass the default value twice?All reactions