1- import { _tuple } from "./api.js" ;
1+ import { _array , _tuple , _unknown } from "./api.js" ;
22
33import { parse , parseAsync } from "./parse.js" ;
44import * as schemas from "./schemas.js" ;
@@ -22,41 +22,29 @@ export interface $ZodFunctionDef<
2222}
2323
2424export type $ZodFunctionArgs = schemas . $ZodType < unknown [ ] , unknown [ ] > ;
25- export type $ZodFunctionIn = $ZodFunctionArgs | null ;
26- export type $ZodFunctionOut = schemas . $ZodType | null ;
25+ export type $ZodFunctionIn = $ZodFunctionArgs ;
26+ export type $ZodFunctionOut = schemas . $ZodType ;
2727
2828export type $InferInnerFunctionType < Args extends $ZodFunctionIn , Returns extends $ZodFunctionOut > = (
29- ...args : null extends Args ? never [ ] : NonNullable < Args > [ "_zod" ] [ "output" ]
30- ) => null extends Returns ? unknown : NonNullable < Returns > [ "_zod" ] [ "input" ] ;
29+ ...args : $ZodFunctionIn extends Args ? never [ ] : Args [ "_zod" ] [ "output" ]
30+ ) => Returns [ "_zod" ] [ "input" ] ;
3131
3232export type $InferInnerFunctionTypeAsync < Args extends $ZodFunctionIn , Returns extends $ZodFunctionOut > = (
33- ...args : null extends Args ? never [ ] : NonNullable < Args > [ "_zod" ] [ "output" ]
34- ) => null extends Returns ? unknown : util . MaybeAsync < NonNullable < Returns > [ "_zod" ] [ "input" ] > ;
35-
36- // export type $InferOuterFunctionType<Args extends $ZodFunctionIn, Returns extends $ZodFunctionOut> = (
37- // ...args: null extends Args ? never[] : NonNullable<Args>["_zod"]["input"]
38- // ) => null extends Returns ? unknown : NonNullable<Returns>["_zod"]["output"];
39- export interface $InferOuterFunctionType < Args extends $ZodFunctionIn , Returns extends $ZodFunctionOut > {
40- // biome-ignore lint:
41- (
42- ...args : null extends Args ? [ ] : NonNullable < Args > [ "_zod" ] [ "input" ]
43- ) : null extends Returns ? unknown : NonNullable < Returns > [ "_zod" ] [ "output" ] ;
44- }
33+ ...args : $ZodFunctionIn extends Args ? never [ ] : Args [ "_zod" ] [ "output" ]
34+ ) => util . MaybeAsync < Returns [ "_zod" ] [ "input" ] > ;
35+
36+ export type $InferOuterFunctionType < Args extends $ZodFunctionIn , Returns extends $ZodFunctionOut > = (
37+ ...args : $ZodFunctionIn extends Args ? never [ ] : Args [ "_zod" ] [ "input" ]
38+ ) => Returns [ "_zod" ] [ "output" ] ;
4539
4640export type $InferOuterFunctionTypeAsync < Args extends $ZodFunctionIn , Returns extends $ZodFunctionOut > = (
47- ...args : null extends Args ? never [ ] : NonNullable < Args > [ "_zod" ] [ "input" ]
48- ) => null extends Returns ? unknown : util . MaybeAsync < NonNullable < Returns > [ "_zod" ] [ "output" ] > ;
41+ ...args : $ZodFunctionIn extends Args ? never [ ] : Args [ "_zod" ] [ "input" ]
42+ ) => util . MaybeAsync < Returns [ "_zod" ] [ "output" ] > ;
4943
5044export class $ZodFunction <
5145 Args extends $ZodFunctionIn = $ZodFunctionIn ,
5246 Returns extends $ZodFunctionOut = $ZodFunctionOut ,
5347> {
54- // _zod!: {
55- // def: $ZodFunctionDef<Args, Returns>;
56- // input: $InferInnerFunctionType<Args, Returns>;
57- // output: $InferOuterFunctionType<Args, Returns>;
58- // };
59-
6048 def : $ZodFunctionDef < Args , Returns > ;
6149
6250 /** @deprecated */
@@ -72,9 +60,9 @@ export class $ZodFunction<
7260 implement < F extends $InferInnerFunctionType < Args , Returns > > (
7361 func : F
7462 ) : // allow for return type inference
75- ReturnType < F > extends ReturnType < this [ "_output" ] >
76- ? ( ...args : Parameters < this[ "_output" ] > ) => ReturnType < F >
77- : this[ "_output" ] {
63+ (
64+ ...args : Parameters < this[ "_output" ] >
65+ ) => ReturnType < F > extends ReturnType < this [ "_output" ] > ? ReturnType < F > : ReturnType < this[ "_output" ] > {
7866 if ( typeof func !== "function" ) {
7967 throw new Error ( "implement() must be called with a function" ) ;
8068 }
@@ -107,7 +95,7 @@ export class $ZodFunction<
10795 return impl ;
10896 }
10997
110- input < const Items extends util . TupleItems , const Rest extends $ZodFunctionOut = null > (
98+ input < const Items extends util . TupleItems , const Rest extends $ZodFunctionOut = $ZodFunctionOut > (
11199 args : Items ,
112100 rest ?: Rest
113101 ) : $ZodFunction < schemas . $ZodTuple < Items , Rest > , Returns > ;
@@ -148,13 +136,13 @@ export interface $ZodFunctionParams<I extends $ZodFunctionIn, O extends schemas.
148136function _function ( ) : $ZodFunction ;
149137function _function < const In extends Array < schemas . $ZodType > = Array < schemas . $ZodType > > ( params : {
150138 input : In ;
151- } ) : $ZodFunction < $ZodTuple < In , null > , null > ;
139+ } ) : $ZodFunction < $ZodTuple < In , null > , $ZodFunctionOut > ;
152140function _function < const In extends $ZodFunctionIn = $ZodFunctionIn > ( params : {
153141 input : In ;
154- } ) : $ZodFunction < In , null > ;
142+ } ) : $ZodFunction < In , $ZodFunctionOut > ;
155143function _function < const Out extends $ZodFunctionOut = $ZodFunctionOut > ( params : {
156144 output : Out ;
157- } ) : $ZodFunction < null , Out > ;
145+ } ) : $ZodFunction < $ZodFunctionIn , Out > ;
158146function _function <
159147 In extends $ZodFunctionIn = $ZodFunctionIn ,
160148 Out extends schemas . $ZodType = schemas . $ZodType ,
@@ -168,8 +156,10 @@ function _function(params?: {
168156} ) : any {
169157 return new $ZodFunction ( {
170158 type : "function" ,
171- input : Array . isArray ( params ?. input ) ? _tuple ( schemas . $ZodTuple , params ?. input as any ) : ( params ?. input ?? null ) ,
172- output : params ?. output ?? null ,
159+ input : Array . isArray ( params ?. input )
160+ ? _tuple ( schemas . $ZodTuple , params ?. input as any )
161+ : ( params ?. input ?? _array ( schemas . $ZodArray , _unknown ( schemas . $ZodUnknown ) ) ) ,
162+ output : params ?. output ?? _unknown ( schemas . $ZodUnknown ) ,
173163 } ) ;
174164}
175165
0 commit comments