Zod - instanceof z.ZodError
For some reason, the error is not being recognized as an instanceof Zod and I have no idea why. Anything wrong I am not seeing?
try {
coursePOST.body.parse(requestBody);
} catch (error) {
if (error instanceof z.ZodError) {
setError(error.issues[0].message);
}
return;
}try {
person.parse({
names: ["Dave", 12], // 12 is not a string
address: {
line1: "123 Maple Ave",
zipCode: 123, // zip code isn't 5 digits
extra: "other stuff", // unrecognized key
},
});
} catch (err) {
if (err instanceof z.ZodError) {
console.log(err.issues);
}
}