@@ -226,9 +226,9 @@ type _FlattenedError<T, U = string> = {
226226
227227export function flattenError < T > ( error : $ZodError < T > ) : _FlattenedError < T > ;
228228export function flattenError < T , U > ( error : $ZodError < T > , mapper ?: ( issue : $ZodIssue ) => U ) : _FlattenedError < T , U > ;
229- export function flattenError ( error : $ZodError , mapper = ( issue : $ZodIssue ) => issue . message ) : any {
230- const fieldErrors : any = { } ;
231- const formErrors : any [ ] = [ ] ;
229+ export function flattenError < T , U > ( error : $ZodError < T > , mapper = ( issue : $ZodIssue ) => issue . message as U ) {
230+ const fieldErrors : Record < PropertyKey , any > = { } ;
231+ const formErrors : U [ ] = [ ] ;
232232 for ( const sub of error . issues ) {
233233 if ( sub . path . length > 0 ) {
234234 fieldErrors [ sub . path [ 0 ] ! ] = fieldErrors [ sub . path [ 0 ] ! ] || [ ] ;
@@ -254,12 +254,7 @@ export type $ZodFormattedError<T, U = string> = {
254254
255255export function formatError < T > ( error : $ZodError < T > ) : $ZodFormattedError < T > ;
256256export function formatError < T , U > ( error : $ZodError < T > , mapper ?: ( issue : $ZodIssue ) => U ) : $ZodFormattedError < T , U > ;
257- export function formatError < T > ( error : $ZodError , _mapper ?: any ) {
258- const mapper : ( issue : $ZodIssue ) => any =
259- _mapper ||
260- function ( issue : $ZodIssue ) {
261- return issue . message ;
262- } ;
257+ export function formatError < T , U > ( error : $ZodError < T > , mapper = ( issue : $ZodIssue ) => issue . message as U ) {
263258 const fieldErrors : $ZodFormattedError < T > = { _errors : [ ] } as any ;
264259 const processError = ( error : { issues : $ZodIssue [ ] } ) => {
265260 for ( const issue of error . issues ) {
@@ -307,13 +302,8 @@ export type $ZodErrorTree<T, U = string> = T extends util.Primitive
307302
308303export function treeifyError < T > ( error : $ZodError < T > ) : $ZodErrorTree < T > ;
309304export function treeifyError < T , U > ( error : $ZodError < T > , mapper ?: ( issue : $ZodIssue ) => U ) : $ZodErrorTree < T , U > ;
310- export function treeifyError < T > ( error : $ZodError , _mapper ?: any ) {
311- const mapper : ( issue : $ZodIssue ) => any =
312- _mapper ||
313- function ( issue : $ZodIssue ) {
314- return issue . message ;
315- } ;
316- const result : $ZodErrorTree < T > = { errors : [ ] } as any ;
305+ export function treeifyError < T , U > ( error : $ZodError < T > , mapper = ( issue : $ZodIssue ) => issue . message as U ) {
306+ const result : $ZodErrorTree < T , U > = { errors : [ ] } as any ;
317307 const processError = ( error : { issues : $ZodIssue [ ] } , path : PropertyKey [ ] = [ ] ) => {
318308 for ( const issue of error . issues ) {
319309 if ( issue . code === "invalid_union" && issue . errors . length ) {
0 commit comments