Skip to content

Commit

Permalink
Clean up type signature of ZodFormattedError
Browse files Browse the repository at this point in the history
  • Loading branch information
Colin McDonnell committed May 6, 2022
1 parent f814ef2 commit c190a84
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
17 changes: 9 additions & 8 deletions deno/lib/ZodError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export type ZodFormattedError<T, U = string> = {
} & (T extends [any, ...any[]]
? { [K in keyof T]?: ZodFormattedError<T[K]> }
: T extends any[]
? ZodFormattedError<T[number]>[]
? { [k: number]: ZodFormattedError<T[number]> }
: T extends object
? { [K in keyof T]?: ZodFormattedError<T[K]> }
: unknown);
Expand Down Expand Up @@ -210,13 +210,14 @@ export class ZodError<T = any> extends Error {
const terminal = i === issue.path.length - 1;

if (!terminal) {
if (typeof el === "string") {
curr[el] = curr[el] || { _errors: [] };
} else if (typeof el === "number") {
const errorArray: any = [];
errorArray._errors = [];
curr[el] = curr[el] || errorArray;
}
curr[el] = curr[el] || { _errors: [] };
// if (typeof el === "string") {
// curr[el] = curr[el] || { _errors: [] };
// } else if (typeof el === "number") {
// const errorArray: any = [];
// errorArray._errors = [];
// curr[el] = curr[el] || errorArray;
// }
} else {
curr[el] = curr[el] || { _errors: [] };
curr[el]._errors.push(mapper(issue));
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zod",
"version": "3.15.0",
"version": "3.15.1",
"description": "TypeScript-first schema declaration and validation library with static type inference",
"main": "./lib/index.js",
"types": "./index.d.ts",
Expand Down
17 changes: 9 additions & 8 deletions src/ZodError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export type ZodFormattedError<T, U = string> = {
} & (T extends [any, ...any[]]
? { [K in keyof T]?: ZodFormattedError<T[K]> }
: T extends any[]
? ZodFormattedError<T[number]>[]
? { [k: number]: ZodFormattedError<T[number]> }
: T extends object
? { [K in keyof T]?: ZodFormattedError<T[K]> }
: unknown);
Expand Down Expand Up @@ -210,13 +210,14 @@ export class ZodError<T = any> extends Error {
const terminal = i === issue.path.length - 1;

if (!terminal) {
if (typeof el === "string") {
curr[el] = curr[el] || { _errors: [] };
} else if (typeof el === "number") {
const errorArray: any = [];
errorArray._errors = [];
curr[el] = curr[el] || errorArray;
}
curr[el] = curr[el] || { _errors: [] };
// if (typeof el === "string") {
// curr[el] = curr[el] || { _errors: [] };
// } else if (typeof el === "number") {
// const errorArray: any = [];
// errorArray._errors = [];
// curr[el] = curr[el] || errorArray;
// }
} else {
curr[el] = curr[el] || { _errors: [] };
curr[el]._errors.push(mapper(issue));
Expand Down

0 comments on commit c190a84

Please sign in to comment.