You need to make sure that shape exists, wrap it with an if (schema instanceof ZodObject) {
shape
if (schema instanceof ZodObject) {