@@ -102,13 +102,19 @@ async function generateTypes() {
102102 } ;
103103
104104 console . log ( ' 📋 First pass: building types map...' ) ;
105+ // Map from name to type string (not type string to name, to avoid collision issues)
106+ const nameToTypeStr = new Map < string , string > ( ) ;
105107 for ( const { schema, name } of schemas ) {
106108 try {
107109 const { node } = zodToTs ( schema , { auxiliaryTypeStore } ) ;
108110 let typeStr = printNode ( node ) ;
109111 // Normalize whitespace for better matching
110112 typeStr = typeStr . replace ( / \s + / g, ' ' ) . trim ( ) ;
111- typesMap . set ( typeStr , name ) ;
113+ nameToTypeStr . set ( name , typeStr ) ;
114+ // Only add to typesMap if not already present (first wins for deduplication)
115+ if ( ! typesMap . has ( typeStr ) ) {
116+ typesMap . set ( typeStr , name ) ;
117+ }
112118 } catch ( error ) {
113119 console . error ( `❌ Failed to generate type for ${ name } :` , error ) ;
114120 }
@@ -121,7 +127,7 @@ async function generateTypes() {
121127 // Sort types by length (longest first) for better matching
122128 const sortedTypes = Array . from ( typesMap . entries ( ) ) . sort ( ( [ a ] , [ b ] ) => b . length - a . length ) ;
123129
124- for ( const [ typeStr , name ] of typesMap ) {
130+ for ( const [ name , typeStr ] of nameToTypeStr ) {
125131 let updatedTypeStr = typeStr ;
126132
127133 // Replace all occurrences of other types with their names (with I prefix)
0 commit comments