@hookform/resolvers 5.4.2 → 5.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/arktype/src/__tests__/__snapshots__/arktype.ts.snap +11 -11
  2. package/arktype/src/__tests__/arktype.ts +15 -6
  3. package/computed-types/src/__tests__/computed-types.ts +15 -6
  4. package/effect-ts/src/__tests__/effect-ts.ts +15 -6
  5. package/io-ts/src/__tests__/io-ts.ts +15 -6
  6. package/package.json +1 -1
  7. package/standard-schema/src/__tests__/__snapshots__/standard-schema.ts.snap +31 -0
  8. package/standard-schema/src/__tests__/standard-schema.ts +21 -13
  9. package/superstruct/dist/superstruct.d.ts +5 -0
  10. package/superstruct/dist/superstruct.js.map +1 -1
  11. package/superstruct/dist/superstruct.modern.mjs.map +1 -1
  12. package/superstruct/dist/superstruct.module.js.map +1 -1
  13. package/superstruct/dist/superstruct.umd.js.map +1 -1
  14. package/superstruct/src/__tests__/superstruct.ts +22 -8
  15. package/superstruct/src/superstruct.ts +13 -0
  16. package/typanion/src/__tests__/typanion.ts +8 -3
  17. package/typebox/src/__tests__/typebox.ts +31 -18
  18. package/typeschema/dist/typeschema.js +1 -1
  19. package/typeschema/dist/typeschema.js.map +1 -1
  20. package/typeschema/dist/typeschema.mjs +1 -1
  21. package/typeschema/dist/typeschema.modern.mjs +1 -1
  22. package/typeschema/dist/typeschema.modern.mjs.map +1 -1
  23. package/typeschema/dist/typeschema.module.js +1 -1
  24. package/typeschema/dist/typeschema.module.js.map +1 -1
  25. package/typeschema/dist/typeschema.umd.js +1 -1
  26. package/typeschema/dist/typeschema.umd.js.map +1 -1
  27. package/typeschema/src/__tests__/typeschema.ts +23 -15
  28. package/typeschema/src/typeschema.ts +6 -6
  29. package/valibot/src/__tests__/valibot.ts +15 -6
  30. package/vine/src/__tests__/vine.ts +15 -6
  31. package/yup/dist/yup.js.map +1 -1
  32. package/yup/dist/yup.modern.mjs.map +1 -1
  33. package/yup/dist/yup.module.js.map +1 -1
  34. package/yup/dist/yup.umd.js.map +1 -1
  35. package/yup/src/__tests__/yup.ts +15 -6
  36. package/yup/src/yup.ts +10 -2
  37. package/zod/dist/zod.js +1 -1
  38. package/zod/dist/zod.js.map +1 -1
  39. package/zod/dist/zod.mjs +1 -1
  40. package/zod/dist/zod.modern.mjs +1 -1
  41. package/zod/dist/zod.modern.mjs.map +1 -1
  42. package/zod/dist/zod.module.js +1 -1
  43. package/zod/dist/zod.module.js.map +1 -1
  44. package/zod/dist/zod.umd.js +1 -1
  45. package/zod/dist/zod.umd.js.map +1 -1
  46. package/zod/src/__tests__/__snapshots__/zod-v3.ts.snap +430 -0
  47. package/zod/src/__tests__/__snapshots__/zod-v4-mini.ts.snap +472 -0
  48. package/zod/src/__tests__/__snapshots__/zod-v4.ts.snap +434 -0
  49. package/zod/src/__tests__/zod-v3.ts +45 -6
  50. package/zod/src/__tests__/zod-v4-mini.ts +21 -11
  51. package/zod/src/__tests__/zod-v4.ts +47 -11
  52. package/zod/src/zod.ts +15 -2
package/zod/src/zod.ts CHANGED
@@ -40,7 +40,14 @@ function parseZod3Issues(
40
40
 
41
41
  if (!errors[_path]) {
42
42
  if ('unionErrors' in error) {
43
- const unionError = error.unionErrors[0].errors[0];
43
+ // Surface the error from whichever union member came closest to
44
+ // matching (fewest issues), rather than always the first member —
45
+ // the first member isn't necessarily the one the input was meant for.
46
+ const closestUnionError = error.unionErrors.reduce(
47
+ (closest, current) =>
48
+ current.errors.length < closest.errors.length ? current : closest,
49
+ );
50
+ const unionError = closestUnionError.errors[0];
44
51
 
45
52
  errors[_path] = {
46
53
  message: unionError.message,
@@ -91,7 +98,13 @@ function parseZod4Issues(
91
98
 
92
99
  if (!errors[_path]) {
93
100
  if (error.code === 'invalid_union' && error.errors.length > 0) {
94
- const unionError = error.errors[0][0];
101
+ // Surface the error from whichever union member came closest to
102
+ // matching (fewest issues), rather than always the first member —
103
+ // the first member isn't necessarily the one the input was meant for.
104
+ const closestBranch = error.errors.reduce((closest, branch) =>
105
+ branch.length < closest.length ? branch : closest,
106
+ );
107
+ const unionError = closestBranch[0];
95
108
 
96
109
  errors[_path] = {
97
110
  message: unionError.message,