Skip to content

Commit

Permalink
Merge pull request #46 from stevent-team/fix/undefined-schema
Browse files Browse the repository at this point in the history
Ignore undefined schemas
  • Loading branch information
GRA0007 authored Aug 21, 2023
2 parents 331d46f + a96199b commit 5cf01c0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/polite-chairs-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@stevent-team/react-zoom-form": patch
---

Fail gracefully if an undefined schema is encountered
6 changes: 4 additions & 2 deletions lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ const getZodObjectShape = (type: z.ZodType) => {
return {}
}

export const unwrapZodType = (type: z.ZodType): z.ZodType => {
export const unwrapZodType = (type: z.ZodType | undefined): z.ZodType | undefined => {
if (type === undefined) return type

if (type instanceof z.ZodObject || type instanceof z.ZodArray) return type

if (type instanceof z.ZodEffects) return unwrapZodType(type.innerType())
Expand All @@ -81,7 +83,7 @@ export const unwrapZodType = (type: z.ZodType): z.ZodType => {
}

const anyType = type as any
if (anyType._def?.innerType) return unwrapZodType(anyType._def.innerType)
if (anyType?._def?.innerType) return unwrapZodType(anyType._def.innerType)

return type
}
Expand Down

0 comments on commit 5cf01c0

Please sign in to comment.