Open Huliiiiii opened 2 months ago
Can't you add an empty value (e.g. empty string)? Feel free to share your use case and code with me.
Can't you add an empty value (e.g. empty string)? Feel free to share your use case and code with me.
No, the schema is an object, and a key of object is string literal union types.
This is my schema:
v.array(
v.object({
language: // Union of language literals,
localized_name: string,
})
)
I understand and will check if we can allow null
or undefined
in such cases. In the meantime, you can change the input requirements of your schema to allow, for example undefined
:
import * as v from 'valibot';
const LanguageSchema = v.picklist(['DE', 'FR', 'US']);
const LanguageArraySchema = v.array(
v.object({
language: v.pipe(v.optional(LanguageSchema), LanguageSchema),
localized_name: v.string(),
})
);
Unfortunately, I couldn't find a quick fix as I encountered some more complex TypeScript errors. I may try again when I have more time or consider it when rewriting the library at some point.
Unfortunately, I couldn't find a quick fix as I encountered some more complex TypeScript errors. I may try again when I have more time or consider it when rewriting the library at some point.
Thanks for your work. For now, changing the schema is a good workaround.
In my case, I need to insert a new entry without value into
FieldArray
, but the current type definition does not support this.