@@ -3295,20 +3295,33 @@ export function generateGoSessionEventsCode(schema: JSONSchema7, packageName: st
32953295 AttachmentTypeGithubReference : "UserMessageAttachmentTypeGithubReference" ,
32963296 AttachmentTypeBlob : "UserMessageAttachmentTypeBlob" ,
32973297 } ;
3298- out . push ( `// Type aliases for convenience.` ) ;
3299- out . push ( `type (` ) ;
3300- for ( const [ alias , target ] of Object . entries ( TYPE_ALIASES ) . sort ( ( [ left ] , [ right ] ) => left . localeCompare ( right ) ) ) {
3301- out . push ( `\t${ alias } = ${ target } ` ) ;
3298+ const generatedTypeNames = new Set ( collectGoTopLevelNames ( joinGoCode ( out ) , "type" ) ) ;
3299+ const generatedConstNames = new Set ( collectGoTopLevelNames ( joinGoCode ( out ) , "const" ) ) ;
3300+ const typeAliases = Object . entries ( TYPE_ALIASES )
3301+ . filter ( ( [ alias , target ] ) => generatedTypeNames . has ( target ) && ! generatedTypeNames . has ( alias ) )
3302+ . sort ( ( [ left ] , [ right ] ) => left . localeCompare ( right ) ) ;
3303+ const constAliases = Object . entries ( CONST_ALIASES )
3304+ . filter ( ( [ alias , target ] ) => generatedConstNames . has ( target ) && ! generatedConstNames . has ( alias ) )
3305+ . sort ( ( [ left ] , [ right ] ) => left . localeCompare ( right ) ) ;
3306+ if ( typeAliases . length > 0 ) {
3307+ out . push ( `// Type aliases for convenience.` ) ;
3308+ out . push ( `type (` ) ;
3309+ for ( const [ alias , target ] of typeAliases ) {
3310+ out . push ( `\t${ alias } = ${ target } ` ) ;
3311+ }
3312+ out . push ( `)` ) ;
3313+ out . push ( `` ) ;
33023314 }
3303- out . push ( `)` ) ;
3304- out . push ( `` ) ;
3305- out . push ( `// Constant aliases for convenience.` ) ;
3306- out . push ( `const (` ) ;
3307- for ( const [ alias , target ] of Object . entries ( CONST_ALIASES ) . sort ( ( [ left ] , [ right ] ) => left . localeCompare ( right ) ) ) {
3308- out . push ( `\t${ alias } = ${ target } ` ) ;
3315+
3316+ if ( constAliases . length > 0 ) {
3317+ out . push ( `// Constant aliases for convenience.` ) ;
3318+ out . push ( `const (` ) ;
3319+ for ( const [ alias , target ] of constAliases ) {
3320+ out . push ( `\t${ alias } = ${ target } ` ) ;
3321+ }
3322+ out . push ( `)` ) ;
3323+ out . push ( `` ) ;
33093324 }
3310- out . push ( `)` ) ;
3311- out . push ( `` ) ;
33123325
33133326 const encodingOut : string [ ] = [ ...sessionEncoding ] ;
33143327 if ( encodingOut . length > 0 ) encodingOut . push ( "" ) ;
0 commit comments