@@ -13,6 +13,7 @@ import {
13
13
parseDeclarationReference ,
14
14
} from "./declarationReference.js" ;
15
15
import { resolveDeclarationReference } from "./declarationReferenceResolver.js" ;
16
+ import { maxElementByScore } from "../../utils/array.js" ;
16
17
17
18
const urlPrefix = / ^ ( h t t p | f t p ) s ? : \/ \/ / ;
18
19
@@ -138,14 +139,32 @@ function resolveLinkTag(
138
139
139
140
if ( tsTargets . length ) {
140
141
// Find the target most likely to have a real url in the generated documentation
141
- target =
142
- tsTargets . find ( ( r ) => r . kindOf ( ReflectionKind . SomeExport ) ) ||
143
- tsTargets . find (
144
- ( r ) =>
145
- r . kindOf ( ReflectionKind . SomeMember ) &&
146
- r . parent ?. kindOf ( ReflectionKind . SomeExport ) ,
147
- ) ||
148
- tsTargets [ 0 ] ;
142
+ // 1. A direct export (class, interface, variable)
143
+ // 2. A property of a direct export (class/interface property)
144
+ // 3. A property of a type of an export (property on type alias)
145
+ // 4. Whatever the first symbol found was
146
+ target = maxElementByScore ( tsTargets , ( r ) => {
147
+ if ( r . kindOf ( ReflectionKind . SomeExport ) ) {
148
+ return 4 ;
149
+ }
150
+ if (
151
+ r . kindOf ( ReflectionKind . SomeMember ) &&
152
+ r . parent ?. kindOf ( ReflectionKind . SomeExport )
153
+ ) {
154
+ return 3 ;
155
+ }
156
+ if (
157
+ r . kindOf ( ReflectionKind . SomeMember ) &&
158
+ r . parent ?. kindOf ( ReflectionKind . TypeLiteral ) &&
159
+ r . parent . parent ?. kindOf (
160
+ ReflectionKind . TypeAlias | ReflectionKind . Variable ,
161
+ )
162
+ ) {
163
+ return 2 ;
164
+ }
165
+
166
+ return 1 ;
167
+ } ) ! ;
149
168
pos = end ;
150
169
defaultDisplayText =
151
170
part . tsLinkText ||
0 commit comments