Skip to content

Commit

Permalink
fix: add the formatted type in ZodFormattedError type recursion
Browse files Browse the repository at this point in the history
  • Loading branch information
HugoMendes98 committed Sep 18, 2024
1 parent 0c46ca0 commit bd7312f
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/ZodError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,17 +177,17 @@ export const quotelessJson = (obj: any) => {
return json.replace(/"([^"]+)":/g, "$1:");
};

type recursiveZodFormattedError<T> = T extends [any, ...any[]]
? { [K in keyof T]?: ZodFormattedError<T[K]> }
type recursiveZodFormattedError<T, U = string> = T extends [any, ...any[]]
? { [K in keyof T]?: ZodFormattedError<T[K], U> }
: T extends any[]
? { [k: number]: ZodFormattedError<T[number]> }
? { [k: number]: ZodFormattedError<T[number], U> }
: T extends object
? { [K in keyof T]?: ZodFormattedError<T[K]> }
? { [K in keyof T]?: ZodFormattedError<T[K], U> }
: unknown;

export type ZodFormattedError<T, U = string> = {
_errors: U[];
} & recursiveZodFormattedError<NonNullable<T>>;
} & recursiveZodFormattedError<NonNullable<T>, U>;

export type inferFormattedError<
T extends ZodType<any, any, any>,
Expand Down

0 comments on commit bd7312f

Please sign in to comment.