import { z } from "zod";
export default z
.union([
z
.object({
from: z.number().optional(),
to: z.number().optional(),
})
.catchall(z.never()),
z
.object({
type: z.union([
z.literal(1),
z.literal(2),
z.literal(3)
]),
})
.catchall(z.never()),
])
Now when the data is parsed I get an empty object because DateRange allows empty properties and other properties are not prohibited by generated schema:
const result = schema.safeParse({ type: 1 });
if (result.success) {
console.log(result.data); // => { }
}
It would be useful if this library supported strict option.
Consider the following type
DateRangeExtended
:The generated zod schema:
Now when the data is parsed I get an empty object because
DateRange
allows empty properties and other properties are not prohibited by generated schema:It would be useful if this library supported strict option.