@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.
- package/arktype/src/__tests__/__snapshots__/arktype.ts.snap +11 -11
- package/arktype/src/__tests__/arktype.ts +15 -6
- package/computed-types/src/__tests__/computed-types.ts +15 -6
- package/effect-ts/src/__tests__/effect-ts.ts +15 -6
- package/io-ts/src/__tests__/io-ts.ts +15 -6
- package/package.json +1 -1
- package/standard-schema/src/__tests__/__snapshots__/standard-schema.ts.snap +31 -0
- package/standard-schema/src/__tests__/standard-schema.ts +21 -13
- package/superstruct/dist/superstruct.d.ts +5 -0
- package/superstruct/dist/superstruct.js.map +1 -1
- package/superstruct/dist/superstruct.modern.mjs.map +1 -1
- package/superstruct/dist/superstruct.module.js.map +1 -1
- package/superstruct/dist/superstruct.umd.js.map +1 -1
- package/superstruct/src/__tests__/superstruct.ts +22 -8
- package/superstruct/src/superstruct.ts +13 -0
- package/typanion/src/__tests__/typanion.ts +8 -3
- package/typebox/src/__tests__/typebox.ts +31 -18
- package/typeschema/dist/typeschema.js +1 -1
- package/typeschema/dist/typeschema.js.map +1 -1
- package/typeschema/dist/typeschema.mjs +1 -1
- package/typeschema/dist/typeschema.modern.mjs +1 -1
- package/typeschema/dist/typeschema.modern.mjs.map +1 -1
- package/typeschema/dist/typeschema.module.js +1 -1
- package/typeschema/dist/typeschema.module.js.map +1 -1
- package/typeschema/dist/typeschema.umd.js +1 -1
- package/typeschema/dist/typeschema.umd.js.map +1 -1
- package/typeschema/src/__tests__/typeschema.ts +23 -15
- package/typeschema/src/typeschema.ts +6 -6
- package/valibot/src/__tests__/valibot.ts +15 -6
- package/vine/src/__tests__/vine.ts +15 -6
- package/yup/dist/yup.js.map +1 -1
- package/yup/dist/yup.modern.mjs.map +1 -1
- package/yup/dist/yup.module.js.map +1 -1
- package/yup/dist/yup.umd.js.map +1 -1
- package/yup/src/__tests__/yup.ts +15 -6
- package/yup/src/yup.ts +10 -2
- package/zod/dist/zod.js +1 -1
- package/zod/dist/zod.js.map +1 -1
- package/zod/dist/zod.mjs +1 -1
- package/zod/dist/zod.modern.mjs +1 -1
- package/zod/dist/zod.modern.mjs.map +1 -1
- package/zod/dist/zod.module.js +1 -1
- package/zod/dist/zod.module.js.map +1 -1
- package/zod/dist/zod.umd.js +1 -1
- package/zod/dist/zod.umd.js.map +1 -1
- package/zod/src/__tests__/__snapshots__/zod-v3.ts.snap +430 -0
- package/zod/src/__tests__/__snapshots__/zod-v4-mini.ts.snap +472 -0
- package/zod/src/__tests__/__snapshots__/zod-v4.ts.snap +434 -0
- package/zod/src/__tests__/zod-v3.ts +45 -6
- package/zod/src/__tests__/zod-v4-mini.ts +21 -11
- package/zod/src/__tests__/zod-v4.ts +47 -11
- 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
|
-
|
|
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
|
-
|
|
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,
|