zod 3.26.0-canary.20250708T090717 → 3.26.0-canary.20250708T225111

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zod",
3
- "version": "3.26.0-canary.20250708T090717",
3
+ "version": "3.26.0-canary.20250708T225111",
4
4
  "type": "module",
5
5
  "author": "Colin McDonnell <zod@colinhacks.com>",
6
6
  "description": "TypeScript-first schema declaration and validation library with static type inference",
@@ -321,7 +321,7 @@ test("all errors", () => {
321
321
  });
322
322
 
323
323
  const schema = z.strictObject({
324
- username: z.string(),
324
+ username: z.string().brand<"username">(),
325
325
  favoriteNumbers: z.array(z.number()),
326
326
  nesting: z.object({
327
327
  a: z.string(),
@@ -336,8 +336,33 @@ const result = schema.safeParse({
336
336
  extra: 1234,
337
337
  });
338
338
 
339
+ const tree = z.treeifyError(result.error!);
340
+
341
+ expectTypeOf(tree).toEqualTypeOf<{
342
+ errors: string[];
343
+ properties?: {
344
+ username?: {
345
+ errors: string[];
346
+ };
347
+ favoriteNumbers?: {
348
+ errors: string[];
349
+ items?: {
350
+ errors: string[];
351
+ }[];
352
+ };
353
+ nesting?: {
354
+ errors: string[];
355
+ properties?: {
356
+ a?: {
357
+ errors: string[];
358
+ };
359
+ };
360
+ };
361
+ };
362
+ }>();
363
+
339
364
  test("z.treeifyError", () => {
340
- expect(z.treeifyError(result.error!)).toMatchInlineSnapshot(`
365
+ expect(tree).toMatchInlineSnapshot(`
341
366
  {
342
367
  "errors": [
343
368
  "Unrecognized key: "extra"",
@@ -295,13 +295,15 @@ export function formatError<T>(error: $ZodError, _mapper?: any) {
295
295
  return fieldErrors;
296
296
  }
297
297
 
298
- export type $ZodErrorTree<T, U = string> = T extends [any, ...any[]]
299
- ? { errors: U[]; items?: { [K in keyof T]?: $ZodErrorTree<T[K], U> } }
300
- : T extends any[]
301
- ? { errors: U[]; items?: Array<$ZodErrorTree<T[number], U>> }
302
- : T extends object
303
- ? { errors: U[]; properties?: { [K in keyof T]?: $ZodErrorTree<T[K], U> } }
304
- : { errors: U[] };
298
+ export type $ZodErrorTree<T, U = string> = T extends util.Primitive
299
+ ? { errors: U[] }
300
+ : T extends [any, ...any[]]
301
+ ? { errors: U[]; items?: { [K in keyof T]?: $ZodErrorTree<T[K], U> } }
302
+ : T extends any[]
303
+ ? { errors: U[]; items?: Array<$ZodErrorTree<T[number], U>> }
304
+ : T extends object
305
+ ? { errors: U[]; properties?: { [K in keyof T]?: $ZodErrorTree<T[K], U> } }
306
+ : { errors: U[] };
305
307
 
306
308
  export function treeifyError<T>(error: $ZodError<T>): $ZodErrorTree<T>;
307
309
  export function treeifyError<T, U>(error: $ZodError<T>, mapper?: (issue: $ZodIssue) => U): $ZodErrorTree<T, U>;
@@ -150,7 +150,9 @@ export type $ZodFormattedError<T, U = string> = {
150
150
  } & util.Flatten<_ZodFormattedError<T, U>>;
151
151
  export declare function formatError<T>(error: $ZodError<T>): $ZodFormattedError<T>;
152
152
  export declare function formatError<T, U>(error: $ZodError<T>, mapper?: (issue: $ZodIssue) => U): $ZodFormattedError<T, U>;
153
- export type $ZodErrorTree<T, U = string> = T extends [any, ...any[]] ? {
153
+ export type $ZodErrorTree<T, U = string> = T extends util.Primitive ? {
154
+ errors: U[];
155
+ } : T extends [any, ...any[]] ? {
154
156
  errors: U[];
155
157
  items?: {
156
158
  [K in keyof T]?: $ZodErrorTree<T[K], U>;
@@ -150,7 +150,9 @@ export type $ZodFormattedError<T, U = string> = {
150
150
  } & util.Flatten<_ZodFormattedError<T, U>>;
151
151
  export declare function formatError<T>(error: $ZodError<T>): $ZodFormattedError<T>;
152
152
  export declare function formatError<T, U>(error: $ZodError<T>, mapper?: (issue: $ZodIssue) => U): $ZodFormattedError<T, U>;
153
- export type $ZodErrorTree<T, U = string> = T extends [any, ...any[]] ? {
153
+ export type $ZodErrorTree<T, U = string> = T extends util.Primitive ? {
154
+ errors: U[];
155
+ } : T extends [any, ...any[]] ? {
154
156
  errors: U[];
155
157
  items?: {
156
158
  [K in keyof T]?: $ZodErrorTree<T[K], U>;