Why does a string array return string[] | undefined
with a default value?
#460
-
I am parsing an object and I'm hoping to have the typescript return with a default value, at the moment I'm receiving an import {
array,
fallback,
optional,
parse,
string,
} from "valibot/mod.ts";
const refreshInit = optional(object({
// ...
ignoreKinds: fallback(array(string()), ["any", "access"] as const),
// ...
}), {ignoreKinds: ['any', 'access']}); I have tried the following, which seems to work on primitive values. ignoreKinds: optional(array(string()), ["any", "access"] as const), |
Beta Was this translation helpful? Give feedback.
Answered by
fabian-hiller
Feb 28, 2024
Replies: 1 comment 1 reply
-
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[] } |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
indifferentghost
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Unfortunately, I don't quite understand what you mean. Everything works as it should for me. Can you explain it in more detail?