Skip to content

Conversation

TaekwanMin
Copy link

@TaekwanMin TaekwanMin commented Jul 18, 2025

🔎 Overview

This PR fixes warnings that occur when describing paths for nested array fields in Zod schemas. The getSchemaForPath function was incorrectly handling array traversal, causing console warnings like:

Failed to describe path buttons[0].link on the schema, returning a default description.

The fixes include:

  1. Corrected loop boundary from i <= paths.length to i < paths.length
  2. Fixed array element access to use element property instead of type
  3. Reordered condition checks to handle array schemas before object schemas
  4. Added proper control flow with continue statements
  5. Enhanced type checking functions with fallback logic for compatibility

🤓 Code snippets/examples (if applicable)

// The warning was caused by incorrect array traversal:
// Before:
if (isIndex(p) && isArraySchema(currentSchema)) {
  currentSchema = (currentSchema._def as ZodArrayDef).type;  // Wrong property
  // Missing continue, causing premature null return
}

// After:
if (isArraySchema(currentSchema) && isIndex(p)) {
  currentSchema = (currentSchema._def as ZodArrayDef).element;  // Correct property
  continue;  // Proper flow control
}

// Also fixed the loop boundary:
// Before: for (let i = 0; i <= paths.length; i++)  // Out of bounds
// After:  for (let i = 0; i < paths.length; i++)   // Correct

// Enhanced type checking for better compatibility:
function getDefType(schema: ZodSchema): ZodFirstPartyTypeKind | undefined {
  if (schema._def && (schema._def as any).typeName) {
    return (schema._def as any).typeName as ZodFirstPartyTypeKind;
  }
  // Added fallback for different Zod versions
  if (schema._def && (schema._def as any).type) {
    if ((schema._def as any).type === 'array') return ZodFirstPartyTypeKind.ZodArray;
    if ((schema._def as any).type === 'object') return ZodFirstPartyTypeKind.ZodObject;
  }
  return undefined;
}

With these changes, paths like buttons[2].link or items[0].variants[1].price are now correctly resolved without warnings.

Issues affected

This resolves console warnings when using nested array fields in Zod schemas with vee-validate's describe method.

Copy link

changeset-bot bot commented Jul 18, 2025

⚠️ No Changeset found

Latest commit: 533b7ac

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

netlify bot commented Jul 18, 2025

Deploy Preview for vee-validate-docs canceled.

Name Link
🔨 Latest commit 533b7ac
🔍 Latest deploy log https://app.netlify.com/projects/vee-validate-docs/deploys/6879fbedfa9aff00087e5599

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant