Skip to content

Why does a string array return string[] | undefined with a default value? #460

Closed Answered by fabian-hiller
indifferentghost asked this question in Q&A
Discussion options

You must be logged in to vote

Unfortunately, I don't quite understand what you mean. Everything works as it should for me. Can you explain it in more detail?

import * as v from 'valibot';

const Schema = v.optional(
  v.object({
    key: v.array(v.string()),
  }),
  { key: ['foo'] }
);

type Input = v.Input<typeof Schema>; // { key: string[] } | undefined
type Output = v.Output<typeof Schema>; // { key: string[] }
import * as v from 'valibot';

const Schema = v.object({
  key: v.optional(v.array(v.string()), ['foo']),
});

type Input = v.Input<typeof Schema>; // { key?: string[] | undefined }
type Output = v.Output<typeof Schema>; // { key: string[] }

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@indifferentghost
Comment options

Answer selected by indifferentghost
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants