Skip to content

Commit a0aa060

Browse files
committed
Link to type parameters on functions/classes
Resolves #2322
1 parent 5e108b6 commit a0aa060

File tree

23 files changed

+281
-125
lines changed

23 files changed

+281
-125
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Features
44

5+
- Type parameters on functions/classes can will now link to the "Type Parameters" section, #2322.
6+
Type parameters have also been changed to have a distinct color from type aliases when rendering, which can be changed with custom CSS.
57
- TypeDoc now provides warnings if a signature comment is directly specified on a signature and contains `@param` tags which do not apply, #2368.
68
- Extended reflection preview view for interfaces to include type parameters, #2455.
79
- Added special cases for converting methods which are documented as returning `this` or accepting `this` as a parameter, #2458.

src/lib/converter/context.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,9 +308,6 @@ export class Context {
308308
);
309309
}
310310

311-
/**
312-
* @param callback The callback function that should be executed with the changed context.
313-
*/
314311
public withScope(scope: Reflection): Context {
315312
const context = new Context(
316313
this.converter,

src/lib/converter/converter.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,6 @@ export class Converter extends ChildableComponent<
254254
* Convert the given TypeScript type into its TypeDoc type reflection.
255255
*
256256
* @param context The context object describing the current state the converter is in.
257-
* @param referenceTarget The target to be used to attempt to resolve reference types
258257
* @returns The TypeDoc type reflection representing the given node and type.
259258
* @internal
260259
*/

src/lib/models/comments/comment.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,6 @@ export class Comment {
387387
* Return the first tag with the given name.
388388
*
389389
* @param tagName The name of the tag to look for.
390-
* @param paramName An optional parameter name to look for.
391390
* @returns The found tag or undefined.
392391
*/
393392
getTag(tagName: `@${string}`): CommentTag | undefined {

src/lib/models/reflections/abstract.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ export abstract class Reflection {
440440
/**
441441
* Return a child by its name.
442442
*
443-
* @param names The name hierarchy of the child to look for.
443+
* @param arg The name hierarchy of the child to look for.
444444
* @returns The found child or undefined.
445445
*/
446446
getChildByName(arg: string | string[]): Reflection | undefined {

src/lib/models/types.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -912,23 +912,15 @@ export class ReferenceType extends Type {
912912
context: Context,
913913
name?: string,
914914
) {
915-
// Type parameters should never have resolved references because they
916-
// cannot be linked to, and might be declared within the type with conditional types.
917-
if (symbol.flags & ts.SymbolFlags.TypeParameter) {
918-
const ref = ReferenceType.createBrokenReference(
919-
name ?? symbol.name,
920-
context.project,
921-
);
922-
ref.refersToTypeParameter = true;
923-
return ref;
924-
}
925-
926915
const ref = new ReferenceType(
927916
name ?? symbol.name,
928917
new ReflectionSymbolId(symbol),
929918
context.project,
930919
getQualifiedName(symbol, name ?? symbol.name),
931920
);
921+
ref.refersToTypeParameter = !!(
922+
symbol.flags & ts.SymbolFlags.TypeParameter
923+
);
932924

933925
const symbolPath = symbol?.declarations?.[0]
934926
?.getSourceFile()

src/lib/output/themes/default/DefaultTheme.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
SignatureReflection,
1010
ReflectionCategory,
1111
ReflectionGroup,
12+
TypeParameterReflection,
1213
} from "../../../models";
1314
import { RenderTemplate, UrlMapping } from "../../models/UrlMapping";
1415
import type { PageEvent } from "../../events";
@@ -121,7 +122,6 @@ export class DefaultTheme extends Theme {
121122
* Create a new DefaultTheme instance.
122123
*
123124
* @param renderer The renderer this theme is attached to.
124-
* @param basePath The base path of this theme.
125125
*/
126126
constructor(renderer: Renderer) {
127127
super(renderer);
@@ -336,7 +336,11 @@ export class DefaultTheme extends Theme {
336336
* @param container The nearest reflection having an own document.
337337
*/
338338
static applyAnchorUrl(reflection: Reflection, container: Reflection) {
339-
if (!(reflection instanceof DeclarationReflection) && !(reflection instanceof SignatureReflection)) {
339+
if (
340+
!(reflection instanceof DeclarationReflection) &&
341+
!(reflection instanceof SignatureReflection) &&
342+
!(reflection instanceof TypeParameterReflection)
343+
) {
340344
return;
341345
}
342346

src/lib/output/themes/default/partials/type.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,11 @@ const typeRenderers: {
276276

277277
if (reflection) {
278278
if (reflection.kindOf(ReflectionKind.TypeParameter)) {
279-
// Don't generate a link as it will always point to this page.
280-
name = <span class="tsd-signature-type tsd-kind-type-parameter">{reflection.name}</span>;
279+
name = (
280+
<a class="tsd-signature-type tsd-kind-type-parameter" href={context.urlTo(reflection)}>
281+
{reflection.name}
282+
</a>
283+
);
281284
} else {
282285
name = renderUniquePath(context, reflection);
283286
}
@@ -290,7 +293,7 @@ const typeRenderers: {
290293
} else if (type.refersToTypeParameter) {
291294
name = <span class="tsd-signature-type tsd-kind-type-parameter">{type.name}</span>;
292295
} else {
293-
name = <span class="tsd-signature-type ">{type.name}</span>;
296+
name = <span class="tsd-signature-type">{type.name}</span>;
294297
}
295298

296299
if (type.typeArguments?.length) {

src/lib/output/themes/default/partials/typeParameters.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@ export function typeParameters(context: DefaultThemeRenderContext, typeParameter
1111
{typeParameters?.map((item) => (
1212
<li>
1313
<h4>
14-
{item.flags.isConst && "const "}
15-
{item.varianceModifier ? `${item.varianceModifier} ` : ""}
14+
<a id={item.anchor} class="tsd-anchor"></a>
15+
{item.flags.isConst && <span class="tsd-signature-keyword">const </span>}
16+
{item.varianceModifier && (
17+
<span class="tsd-signature-keyword">{item.varianceModifier} </span>
18+
)}
1619
<span class="tsd-kind-type-parameter">{item.name}</span>
1720
{!!item.type && (
1821
<>

src/lib/output/themes/lib.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@ export function renderTypeParametersSignature(
108108
<>
109109
{item.flags.isConst && <span class="tsd-signature-keyword">const </span>}
110110
{item.varianceModifier ? `${item.varianceModifier} ` : ""}
111-
<span class="tsd-signature-type tsd-kind-type-parameter">{item.name}</span>
111+
<a class="tsd-signature-type tsd-kind-type-parameter" href={context.urlTo(item)}>
112+
{item.name}
113+
</a>
112114
</>
113115
))}
114116
<span class="tsd-signature-symbol">{">"}</span>

0 commit comments

Comments
 (0)