I've searched through the documentation but find no solution for this case. I've got the following schemas.
const RelationSchema = z.object({
guid: z.string(),
createdDate: z.preprocess(castToDate, z.date()),
modifiedDate: z.preprocess(castToDate, z.date()).nullable(),
name: z.string(),
publicationtype: z.string(),
contentType: z.string(),
});
export const NobbRelationsSchema = z.array(NobbRelationSchema);
When parsing an array with NobbRelationsSchema.parse() I sometimes get back name as undefined. In these cases I would like Zod not to throw an error, but instead just remove that element and continue with the rest. A kind of filtering.
The option I see is to use safeParse and set name as optional and filter out these afterwards. However, it messes up the TypeScript type checking later in code, as name should always be set for valid elements.