@@ -37,6 +37,32 @@ export function resolveType(
3737 typeStack . push ( typeId ) ;
3838 }
3939
40+ function areEquivalent ( typeNodeName : ts . EntityName , type : ts . Type ) : boolean | undefined {
41+ if ( ts . isIdentifier ( typeNodeName ) ) {
42+ const typeSymbolCandidate = checker . getSymbolAtLocation ( typeNodeName ) ;
43+ if ( ! typeSymbolCandidate ) {
44+ return undefined ;
45+ }
46+
47+ return (
48+ typeNodeName . text === type . aliasSymbol ?. name &&
49+ getTypeSymbolNamespaces ( typeSymbolCandidate ) . join ( '.' ) === getTypeNamespaces ( type ) . join ( '.' )
50+ ) ;
51+ } else if ( ts . isQualifiedName ( typeNodeName ) ) {
52+ const typeSymbolCandidate = checker . getSymbolAtLocation ( typeNodeName . right ) ;
53+ if ( ! typeSymbolCandidate ) {
54+ return undefined ;
55+ }
56+
57+ return (
58+ typeNodeName . right . text === type . aliasSymbol ?. name &&
59+ getTypeSymbolNamespaces ( typeSymbolCandidate ) . join ( '.' ) === getTypeNamespaces ( type ) . join ( '.' )
60+ ) ;
61+ }
62+
63+ return undefined ;
64+ }
65+
4066 // The following code handles cases where the type is a simple alias of another type (type Alias = SomeType).
4167 // TypeScript resolves the alias automatically, but we want to preserve the original type symbol if it exists.
4268 //
@@ -45,29 +71,19 @@ export function resolveType(
4571 let typeSymbol : ts . Symbol | undefined ;
4672 if ( typeNode && ts . isTypeReferenceNode ( typeNode ) ) {
4773 const typeNodeName = ( typeNode as ts . TypeReferenceNode ) . typeName ;
74+ let typeSymbolCandidate : ts . Symbol | undefined ;
4875 if ( ts . isIdentifier ( typeNodeName ) ) {
49- const typeSymbolCandidate = checker . getSymbolAtLocation ( typeNodeName ) ;
50-
51- if (
52- typeSymbolCandidate &&
53- ( typeNodeName . text !== type . aliasSymbol ?. name ||
54- getTypeSymbolNamespaces ( typeSymbolCandidate ) . join ( '.' ) !==
55- getTypeNamespaces ( type ) . join ( '.' ) ) &&
56- ! ( typeSymbolCandidate . flags & ts . SymbolFlags . TypeParameter )
57- ) {
58- typeSymbol = typeSymbolCandidate ;
59- }
76+ typeSymbolCandidate = checker . getSymbolAtLocation ( typeNodeName ) ;
6077 } else if ( ts . isQualifiedName ( typeNodeName ) ) {
61- const typeSymbolCandidate = checker . getSymbolAtLocation ( typeNodeName . right ) ;
62- if (
63- typeSymbolCandidate &&
64- ( typeNodeName . right . text !== type . aliasSymbol ?. name ||
65- getTypeSymbolNamespaces ( typeSymbolCandidate ) . join ( '.' ) !==
66- getTypeNamespaces ( type ) . join ( '.' ) ) &&
67- ! ( typeSymbolCandidate . flags & ts . SymbolFlags . TypeParameter )
68- ) {
69- typeSymbol = typeSymbolCandidate ;
70- }
78+ typeSymbolCandidate = checker . getSymbolAtLocation ( typeNodeName . right ) ;
79+ }
80+
81+ if (
82+ typeSymbolCandidate &&
83+ ! areEquivalent ( typeNodeName , type ) &&
84+ ! ( typeSymbolCandidate . flags & ts . SymbolFlags . TypeParameter )
85+ ) {
86+ typeSymbol = typeSymbolCandidate ;
7187 }
7288 }
7389
0 commit comments