Skip to content

fix: valibot intersections #5014

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 22, 2025

Conversation

jack-allocate
Copy link
Contributor

🔎 Overview

I use the required field on useField#meta to automatically show an "Optional" text on an input. I found that having intersections in Valibot breaks this. For example, I have a PasswordSchema for reusability:

export const PasswordSchema = v.pipe(
  v.object({
    password: v.pipe(v.string(), v.minLength(8)),
    confirmPassword: v.pipe(v.string(), v.minLength(8)),
  }),
  v.forward(
    v.partialCheck(
      [['password'], ['confirmPassword']],
      (input) => input.password === input.confirmPassword,
      'The two passwords do not match.',
    ),
    ['confirmPassword'],
  ),
)

Which I then use in a form:

const schema = v.object({
  user: v.intersect([
    PasswordSchema,
    v.object({
      email: v.pipe(v.string(), v.email()),
    }),
  ]),
})

This resulted in required always being true.

I've implemented a fix for this along with two test cases.

Copy link

changeset-bot bot commented Mar 25, 2025

🦋 Changeset detected

Latest commit: b4fe519

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 8 packages
Name Type
@vee-validate/valibot Patch
vee-validate Patch
@vee-validate/rules Patch
@vee-validate/i18n Patch
@vee-validate/zod Patch
@vee-validate/yup Patch
@vee-validate/nuxt Patch
@vee-validate/joi Patch

Not sure what this means? Click here to learn what changesets are.

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

Copy link

codecov bot commented Mar 25, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.36%. Comparing base (546d82e) to head (b4fe519).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5014      +/-   ##
==========================================
+ Coverage   89.28%   89.36%   +0.07%     
==========================================
  Files          93       93              
  Lines        8027     8046      +19     
  Branches     1386     1394       +8     
==========================================
+ Hits         7167     7190      +23     
+ Misses        853      849       -4     
  Partials        7        7              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Owner

@logaretm logaretm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, many thanks!

@logaretm logaretm merged commit 9803aa2 into logaretm:main Apr 22, 2025
7 checks passed
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.

2 participants