File tree 7 files changed +25
-17
lines changed
7 files changed +25
-17
lines changed Original file line number Diff line number Diff line change @@ -413,8 +413,12 @@ export const defaultErrorMap = (
413
413
return { message } ;
414
414
} ;
415
415
416
- export let overrideErrorMap = defaultErrorMap ;
416
+ let overrideErrorMap = defaultErrorMap ;
417
417
418
- export const setErrorMap = ( map : ZodErrorMap ) => {
418
+ export function setErrorMap ( map : ZodErrorMap ) {
419
419
overrideErrorMap = map ;
420
- } ;
420
+ }
421
+
422
+ export function getErrorMap ( ) {
423
+ return overrideErrorMap ;
424
+ }
Original file line number Diff line number Diff line change 1
1
import type { IssueData , ZodErrorMap , ZodIssue } from "../ZodError.ts" ;
2
- import { defaultErrorMap , overrideErrorMap } from "../ZodError.ts" ;
2
+ import { defaultErrorMap , getErrorMap } from "../ZodError.ts" ;
3
3
import type { ZodParsedType } from "./util.ts" ;
4
4
5
5
export const makeIssue = ( params : {
@@ -71,7 +71,7 @@ export function addIssueToContext(
71
71
errorMaps : [
72
72
ctx . common . contextualErrorMap , // contextual error map is first priority
73
73
ctx . schemaErrorMap , // then schema-bound map if available
74
- overrideErrorMap , // then global override map
74
+ getErrorMap ( ) , // then global override map
75
75
defaultErrorMap , // then global default map
76
76
] . filter ( ( x ) => ! ! x ) as ZodErrorMap [ ] ,
77
77
} ) ;
Original file line number Diff line number Diff line change @@ -23,8 +23,8 @@ import { Primitive } from "./helpers/typeAliases.ts";
23
23
import { getParsedType , util , ZodParsedType } from "./helpers/util.ts" ;
24
24
import {
25
25
defaultErrorMap ,
26
+ getErrorMap ,
26
27
IssueData ,
27
- overrideErrorMap ,
28
28
StringValidation ,
29
29
ZodCustomIssue ,
30
30
ZodError ,
@@ -2823,7 +2823,7 @@ export class ZodFunction<
2823
2823
errorMaps : [
2824
2824
ctx . common . contextualErrorMap ,
2825
2825
ctx . schemaErrorMap ,
2826
- overrideErrorMap ,
2826
+ getErrorMap ( ) ,
2827
2827
defaultErrorMap ,
2828
2828
] . filter ( ( x ) => ! ! x ) as ZodErrorMap [ ] ,
2829
2829
issueData : {
@@ -2840,7 +2840,7 @@ export class ZodFunction<
2840
2840
errorMaps : [
2841
2841
ctx . common . contextualErrorMap ,
2842
2842
ctx . schemaErrorMap ,
2843
- overrideErrorMap ,
2843
+ getErrorMap ( ) ,
2844
2844
defaultErrorMap ,
2845
2845
] . filter ( ( x ) => ! ! x ) as ZodErrorMap [ ] ,
2846
2846
issueData : {
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " zod" ,
3
- "version" : " 3.17.5 " ,
3
+ "version" : " 3.17.6 " ,
4
4
"description" : " TypeScript-first schema declaration and validation library with static type inference" ,
5
5
"main" : " ./lib/index.js" ,
6
6
"types" : " ./index.d.ts" ,
Original file line number Diff line number Diff line change @@ -413,8 +413,12 @@ export const defaultErrorMap = (
413
413
return { message } ;
414
414
} ;
415
415
416
- export let overrideErrorMap = defaultErrorMap ;
416
+ let overrideErrorMap = defaultErrorMap ;
417
417
418
- export const setErrorMap = ( map : ZodErrorMap ) => {
418
+ export function setErrorMap ( map : ZodErrorMap ) {
419
419
overrideErrorMap = map ;
420
- } ;
420
+ }
421
+
422
+ export function getErrorMap ( ) {
423
+ return overrideErrorMap ;
424
+ }
Original file line number Diff line number Diff line change 1
1
import type { IssueData , ZodErrorMap , ZodIssue } from "../ZodError" ;
2
- import { defaultErrorMap , overrideErrorMap } from "../ZodError" ;
2
+ import { defaultErrorMap , getErrorMap } from "../ZodError" ;
3
3
import type { ZodParsedType } from "./util" ;
4
4
5
5
export const makeIssue = ( params : {
@@ -71,7 +71,7 @@ export function addIssueToContext(
71
71
errorMaps : [
72
72
ctx . common . contextualErrorMap , // contextual error map is first priority
73
73
ctx . schemaErrorMap , // then schema-bound map if available
74
- overrideErrorMap , // then global override map
74
+ getErrorMap ( ) , // then global override map
75
75
defaultErrorMap , // then global default map
76
76
] . filter ( ( x ) => ! ! x ) as ZodErrorMap [ ] ,
77
77
} ) ;
Original file line number Diff line number Diff line change @@ -23,8 +23,8 @@ import { Primitive } from "./helpers/typeAliases";
23
23
import { getParsedType , util , ZodParsedType } from "./helpers/util" ;
24
24
import {
25
25
defaultErrorMap ,
26
+ getErrorMap ,
26
27
IssueData ,
27
- overrideErrorMap ,
28
28
StringValidation ,
29
29
ZodCustomIssue ,
30
30
ZodError ,
@@ -2823,7 +2823,7 @@ export class ZodFunction<
2823
2823
errorMaps : [
2824
2824
ctx . common . contextualErrorMap ,
2825
2825
ctx . schemaErrorMap ,
2826
- overrideErrorMap ,
2826
+ getErrorMap ( ) ,
2827
2827
defaultErrorMap ,
2828
2828
] . filter ( ( x ) => ! ! x ) as ZodErrorMap [ ] ,
2829
2829
issueData : {
@@ -2840,7 +2840,7 @@ export class ZodFunction<
2840
2840
errorMaps : [
2841
2841
ctx . common . contextualErrorMap ,
2842
2842
ctx . schemaErrorMap ,
2843
- overrideErrorMap ,
2843
+ getErrorMap ( ) ,
2844
2844
defaultErrorMap ,
2845
2845
] . filter ( ( x ) => ! ! x ) as ZodErrorMap [ ] ,
2846
2846
issueData : {
You can’t perform that action at this time.
0 commit comments