Skip to content

Commit 1d30df4

Browse files
committed
Add support for @preventExpand and @expandType
Resolves #2862
1 parent 1fe0f1c commit 1d30df4

24 files changed

+3718
-51
lines changed

.vscode/settings.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,12 @@
4242

4343
"eslint.workingDirectories": [".", "./example"],
4444
"mochaExplorer.configFile": ".config/mocha.test-explorer.json",
45-
// Ignore usernames in the Thanks sections of the changelog
46-
"cSpell.ignoreRegExpList": ["/^- +@[A-Z0-9_-]+/igm"],
45+
"cSpell.ignoreRegExpList": [
46+
// Ignore usernames in the Thanks sections of the changelog
47+
"/^- +@[A-Z0-9_-]+/igm",
48+
// Ignore combined hashes in JSON output for rendering testing
49+
"/#[a-z0-9_]+\"/"
50+
],
4751
"cSpell.words": [
4852
"callouts",
4953
"cname",

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ title: Changelog
3535
- `ReflectionKind.singularString` and `ReflectionKind.pluralString` now returns translated strings.
3636
The methods on `Internationalization` to do this previously have been removed.
3737
- The HTML output structure for the search box has changed to support the new modal.
38+
- `DefaultThemeRenderContext`'s `typeDeclaration` and `typeDetailsIfUseful`
39+
methods now require both a reflection and a type in order to support
40+
`@expandType`
3841

3942
### Features
4043

@@ -51,6 +54,7 @@ title: Changelog
5154
- Introduced `@function` tag to force TypeDoc to convert variable declarations with a type annotation as functions, #2881.
5255
- Exposed a `TypeDoc` global object in the HTML theme which can be used to prevent TypeDoc from using `localStorage`, #2872.
5356
- Introduced `@preventInline` and `@inlineType` tags for further control extending the `@inline` tag, #2862.
57+
- Introduced `@preventExpand` and `@expandType` tags for further control extending the `@expand` tag, #2862.
5458
- API: Introduced `DefaultThemeRenderContext.reflectionIcon` for more granular control over displayed reflection icons.
5559

5660
### Bug Fixes

site/tags.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,15 @@ examples for how to use the export ([`@example`](./tags/example.md)).
114114
- [`@deprecated`](./tags/deprecated.md)
115115
- [`@document`](./tags/document.md)
116116
- [`@example`](./tags/example.md)
117+
- [`@expandType`](./tags/expand.md#expandtype)
117118
- [`@group`, `@groupDescription`, `@showGroups`, `@hideGroups`](./tags/group.md)
118119
- [`@import`](./tags/import.md)
119120
- [`@inlineType`](./tags/inline.md#inlinetype)
120121
- [`@license`](./tags/license.md)
121122
- [`@mergeModuleWith`](./tags/mergeModuleWith.md)
122123
- [`@module`](./tags/module.md)
123124
- [`@param`](./tags/param.md)
125+
- [`@preventExpand`](./tags/expand.md#preventexpand)
124126
- [`@preventInline`](./tags/inline.md#preventinline)
125127
- [`@privateRemarks`](./tags/privateRemarks.md)
126128
- [`@property`, `@prop`](./tags/property.md)

site/tags/expand.md

Lines changed: 67 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22
title: "@expand"
33
---
44

5-
# @expand
5+
# Expand Tags
6+
7+
The `@expand`, `@expandType`, and `@preventExpand` tags can be used to control
8+
how TypeDoc _displays_ references to type aliases and interfaces.
9+
10+
## @expand
611

712
**Tag Kind:** [Modifier](../tags.md#modifier-tags)
813

@@ -15,7 +20,7 @@ wherever it is referenced and TypeDoc has a place to include it.
1520
> documentation if it is applied to commonly used types as it will result in
1621
> inlining the comments for those types everywhere they are referenced.
1722
18-
## Example
23+
### Example
1924

2025
This is particularly useful for React components, where the documentation for
2126
props is useful when viewing the component function. The `Hello` component below
@@ -52,6 +57,65 @@ export function Hello2(props: HelloProps) {
5257
}
5358
```
5459

60+
## @expandType
61+
62+
**Tag Kind:** [Block](../tags.md#block-tags)
63+
64+
The `@expandType` can be placed on any reflection to tell TypeDoc to expand a type
65+
reference when rendering it within that reflection. It should specify the type name
66+
without type arguments.
67+
68+
`@expandType` is inherited, it may be placed on a namespace or module where there are
69+
multiple references to a type to instruct TypeDoc to expand the type everywhere in that
70+
module.
71+
72+
### Example
73+
74+
TypeDoc will expand `HelloProps` within `Hello` as if `@expand` had been placed
75+
on `HelloProps`.
76+
77+
```ts
78+
export type HelloProps = {
79+
/** Name description */
80+
name: string;
81+
};
82+
83+
/**
84+
* Hello component
85+
* @expandType HelloProps
86+
*/
87+
export function Hello(props: HelloProps) {
88+
return <span>Hello {props.name}!</span>;
89+
}
90+
```
91+
92+
## @preventExpand
93+
94+
**Tag Kind:** [Block](../tags.md#block-tags)
95+
96+
The `@preventExpand` block tag can be used to instruct TypeDoc to not expand a
97+
tag which has been expanded with `@expand`, `@preventExpand`, or by highlighting
98+
properties of the reference type with `@param`.
99+
100+
```tsx
101+
/**
102+
* @expand
103+
*/
104+
export type HelloProps = {
105+
/** Name property docs */
106+
name: string;
107+
};
108+
109+
/**
110+
* Hello component - HelloProps will NOT be expanded here
111+
* @preventExpand HelloProps
112+
*/
113+
export function Hello2(props: HelloProps) {
114+
return <span>Hello {props.name}!</span>;
115+
}
116+
```
117+
55118
## See Also
56119

57-
- The [`@inline`](inline.md) tag
120+
- The [`@inline`](inline.md) tags
121+
- The [`@param`](param.md) tag

site/tags/inline.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,4 @@ export function Hello2(props: HelloProps) {
9898

9999
## See Also
100100

101-
- The [`@expand`](expand.md) tag
101+
- The [`@expand`](expand.md) tags

src/lib/output/themes/default/partials/member.declaration.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export function memberDeclaration(context: DefaultThemeRenderContext, props: Dec
4343

4444
{hasTypeParameters(props) && context.typeParameters(props.typeParameters)}
4545

46-
{props.type && context.typeDeclaration(props.type)}
46+
{props.type && context.typeDeclaration(props, props.type)}
4747

4848
{context.commentTags(props)}
4949

src/lib/output/themes/default/partials/member.signature.body.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export function memberSignatureBody(
3838
</span>
3939
{context.commentSummary(item)}
4040
{context.commentTags(item)}
41-
{context.typeDetailsIfUseful(item.type)}
41+
{context.typeDetailsIfUseful(item, item.type)}
4242
</li>
4343
))}
4444
</ul>
@@ -50,7 +50,7 @@ export function memberSignatureBody(
5050
{i18n.theme_returns()} {context.type(props.type)}
5151
</h4>
5252
{returnsTag && <JSX.Raw html={context.markdown(returnsTag.content)} />}
53-
{context.typeDetailsIfUseful(props.type)}
53+
{context.typeDetailsIfUseful(props, props.type)}
5454
</>
5555
)}
5656

0 commit comments

Comments
 (0)