@@ -532,6 +532,7 @@ export class Converter {
532532 convertedSet : Set < string > ;
533533 extraTopLevels : TopLevelIR [ ] ;
534534 nameContext : string [ ] | undefined ;
535+ typeMap : Map < number , TypeIR > ;
535536
536537 constructor ( ) {
537538 this . ifaceTypeParamConstraints = new Map ( ) ;
@@ -540,6 +541,7 @@ export class Converter {
540541 this . convertedSet = new Set ( BUILTIN_NAMES ) ;
541542 this . extraTopLevels = [ ] ;
542543 this . nameContext = undefined ;
544+ this . typeMap = new Map ( ) ;
543545 }
544546
545547 pushNameContext ( ctx : string ) : void {
@@ -689,6 +691,20 @@ export class Converter {
689691 return { kind : "other" , nodeKind, location } ;
690692 }
691693
694+ lookupTypeIR ( node : TypeNode ) : TypeIR | undefined {
695+ const t = node . getType ( ) ;
696+ // @ts -expect-error
697+ const id = t . compilerType . id ;
698+ return this . typeMap . get ( id ) ;
699+ }
700+
701+ cacheTypeIR ( node : TypeNode , ir : TypeIR ) : void {
702+ const t = node . getType ( ) ;
703+ // @ts -expect-error
704+ const id = t . compilerType . id ;
705+ this . typeMap . set ( id , ir ) ;
706+ }
707+
692708 maybeSyntheticTypeToIR ( node : TypeNode ) : TypeIR | undefined {
693709 if ( ! this . nameContext ) {
694710 return undefined ;
@@ -697,7 +713,13 @@ export class Converter {
697713 if ( ! typeRoot ) {
698714 return undefined ;
699715 }
700- return new SyntheticTypeConverter ( this ) . classifiedTypeToIr ( typeRoot ) ;
716+ const lookup = this . lookupTypeIR ( node ) ;
717+ if ( lookup ) {
718+ return lookup ;
719+ }
720+ const res = new SyntheticTypeConverter ( this ) . classifiedTypeToIr ( typeRoot ) ;
721+ this . cacheTypeIR ( node , res ) ;
722+ return res ;
701723 }
702724
703725 typeToIR (
0 commit comments