File tree Expand file tree Collapse file tree 4 files changed +24
-8
lines changed
Expand file tree Collapse file tree 4 files changed +24
-8
lines changed Original file line number Diff line number Diff line change @@ -8,13 +8,13 @@ const stringSchema = z.string();
88test ( "safeparse fail" , ( ) => {
99 const safe = stringSchema . safeParse ( 12 ) ;
1010 expect ( safe . success ) . toEqual ( false ) ;
11- expect ( ( safe as any ) . error ) . toBeInstanceOf ( z . ZodError ) ;
11+ expect ( safe . error ) . toBeInstanceOf ( z . ZodError ) ;
1212} ) ;
1313
1414test ( "safeparse pass" , ( ) => {
1515 const safe = stringSchema . safeParse ( "12" ) ;
1616 expect ( safe . success ) . toEqual ( true ) ;
17- expect ( ( safe as any ) . data ) . toEqual ( "12" ) ;
17+ expect ( safe . data ) . toEqual ( "12" ) ;
1818} ) ;
1919
2020test ( "safeparse unexpected error" , ( ) => {
Original file line number Diff line number Diff line change @@ -144,8 +144,16 @@ function processCreateParams(params: RawCreateParams): ProcessedCreateParams {
144144 return { errorMap : customMap , description } ;
145145}
146146
147- export type SafeParseSuccess < Output > = { success : true ; data : Output } ;
148- export type SafeParseError < Input > = { success : false ; error : ZodError < Input > } ;
147+ export type SafeParseSuccess < Output > = {
148+ success : true ;
149+ data : Output ;
150+ error ?: never ;
151+ } ;
152+ export type SafeParseError < Input > = {
153+ success : false ;
154+ error : ZodError < Input > ;
155+ data ?: never ;
156+ } ;
149157
150158export type SafeParseReturnType < Input , Output > =
151159 | SafeParseSuccess < Output >
Original file line number Diff line number Diff line change @@ -7,13 +7,13 @@ const stringSchema = z.string();
77test ( "safeparse fail" , ( ) => {
88 const safe = stringSchema . safeParse ( 12 ) ;
99 expect ( safe . success ) . toEqual ( false ) ;
10- expect ( ( safe as any ) . error ) . toBeInstanceOf ( z . ZodError ) ;
10+ expect ( safe . error ) . toBeInstanceOf ( z . ZodError ) ;
1111} ) ;
1212
1313test ( "safeparse pass" , ( ) => {
1414 const safe = stringSchema . safeParse ( "12" ) ;
1515 expect ( safe . success ) . toEqual ( true ) ;
16- expect ( ( safe as any ) . data ) . toEqual ( "12" ) ;
16+ expect ( safe . data ) . toEqual ( "12" ) ;
1717} ) ;
1818
1919test ( "safeparse unexpected error" , ( ) => {
Original file line number Diff line number Diff line change @@ -144,8 +144,16 @@ function processCreateParams(params: RawCreateParams): ProcessedCreateParams {
144144 return { errorMap : customMap , description } ;
145145}
146146
147- export type SafeParseSuccess < Output > = { success : true ; data : Output } ;
148- export type SafeParseError < Input > = { success : false ; error : ZodError < Input > } ;
147+ export type SafeParseSuccess < Output > = {
148+ success : true ;
149+ data : Output ;
150+ error ?: never ;
151+ } ;
152+ export type SafeParseError < Input > = {
153+ success : false ;
154+ error : ZodError < Input > ;
155+ data ?: never ;
156+ } ;
149157
150158export type SafeParseReturnType < Input , Output > =
151159 | SafeParseSuccess < Output >
You can’t perform that action at this time.
0 commit comments