I'm attempting to define an object type in zod that looks like this:
{
default: string,
[string]: string,
}
I've experimented with combining z.object
and z.record
using z.union
, but the validation results are not as expected.
const LocaleString = z.union([
z
.object({
default: z.string(),
}).required(),
z.record(z.string()),
]);
LocaleString.safeParse({
testing: 'abc',
});
/**
* it will return `{ success: true, data: { testing: 'abc' } }`,
* where I expect it to fail when the data is without a default value
*/