@@ -4,10 +4,12 @@ import type {
44 $ZodDefault ,
55 $ZodDiscriminatedUnion ,
66 $ZodEnum ,
7+ $ZodInterface ,
78 $ZodIntersection ,
89 $ZodLazy ,
910 $ZodLiteral ,
1011 $ZodNullable ,
12+ $ZodObject ,
1113 $ZodOptional ,
1214 $ZodPipe ,
1315 $ZodReadonly ,
@@ -66,7 +68,7 @@ const onLiteral: Producer = ({ _zod: { def } }: $ZodLiteral) => {
6668 return values . length === 1 ? values [ 0 ] : f . createUnionTypeNode ( values ) ;
6769} ;
6870
69- const onInterface : Producer = ( int : z . ZodInterface , { next, makeAlias } ) =>
71+ const onInterface : Producer = ( int : $ ZodInterface, { next, makeAlias } ) =>
7072 makeAlias ( int , ( ) => {
7173 const members = Object . entries ( int . _zod . def . shape ) . map < ts . TypeElement > (
7274 ( [ key , value ] ) => {
@@ -84,16 +86,16 @@ const onInterface: Producer = (int: z.ZodInterface, { next, makeAlias }) =>
8486 } ) ;
8587
8688const onObject : Producer = (
87- { _zod : { def } } : z . ZodObject ,
89+ { _zod : { def } } : $ ZodObject,
8890 { isResponse, next } ,
8991) => {
9092 const members = Object . entries ( def . shape ) . map < ts . TypeElement > (
9193 ( [ key , value ] ) => {
9294 const isOptional = isResponse
93- ? value instanceof z . ZodOptional
94- : value instanceof z . ZodPromise
95- ? false
96- : ( value as z . ZodType ) . isOptional ( ) ;
95+ ? value . _zod . def . type === "optional"
96+ : value . _zod . def . type !== "promise" &&
97+ value instanceof z . ZodType &&
98+ value . isOptional ( ) ;
9799 const { description : comment , deprecated : isDeprecated } =
98100 globalRegistry . get ( value ) || { } ;
99101 return makeInterfaceProp ( key , next ( value ) , {
@@ -211,9 +213,9 @@ const onFile: Producer = (schema: FileSchema) => {
211213 const stringType = ensureTypeNode ( ts . SyntaxKind . StringKeyword ) ;
212214 const bufferType = ensureTypeNode ( "Buffer" ) ;
213215 const unionType = f . createUnionTypeNode ( [ stringType , bufferType ] ) ;
214- return schema instanceof z . ZodString
216+ return schema . _zod . def . type === "string"
215217 ? stringType
216- : schema instanceof z . ZodUnion
218+ : schema . _zod . def . type === "union"
217219 ? unionType
218220 : bufferType ;
219221} ;
0 commit comments