Skip to content

Commit 6de1e38

Browse files
committed
Add question mark when rendering optional property name
Resolves #2023
1 parent 23bde9a commit 6de1e38

File tree

6 files changed

+27
-5
lines changed

6 files changed

+27
-5
lines changed

.config/typedoc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"EventHooksMomento",
1111
"MarkedPlugin"
1212
],
13+
"sort": ["kind", "instance-first", "required-first", "alphabetical"],
1314
"entryPoints": ["../src"],
1415
"entryPointStrategy": "resolve",
1516
"excludeExternals": true,

CHANGELOG.md

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

55
- Added support for detecting comments directly before parameters as the parameter comment, #2019.
66
- Added support for using the comment directly before a constructor parameter that declares a property as the property comment, #2019.
7+
- Improved schema generation to give better autocomplete for the `sort` option.
8+
- Optional properties are now visually distinguished in the index/sidebar by rendering `prop` as `prop?`, #2023.
79

810
### Bug Fixes
911

scripts/generate_options_schema.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ schema.properties.extends = {
153153
items: { type: "string" },
154154
};
155155

156+
delete schema.properties.sort.items.type;
157+
schema.properties.sort.items.enum =
158+
require("../dist/lib/utils/sort").SORT_STRATEGIES;
159+
156160
const output = JSON.stringify(schema, null, "\t");
157161

158162
if (process.argv.length > 2) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { classNames, displayPartsToMarkdown, wbr } from "../../lib";
1+
import { classNames, displayPartsToMarkdown, renderName } from "../../lib";
22
import type { DefaultThemeRenderContext } from "../DefaultThemeRenderContext";
33
import { JSX, Raw } from "../../../../utils";
44
import { ContainerReflection, DeclarationReflection, ReflectionCategory, ReflectionKind } from "../../../../models";
@@ -18,7 +18,7 @@ function renderCategory({ urlTo, icons }: DefaultThemeRenderContext, item: Refle
1818
)}
1919
>
2020
{icons[item.kind]()}
21-
<span>{item.name ? wbr(item.name) : <em>{wbr(item.kindString!)}</em>}</span>
21+
<span>{renderName(item)}</span>
2222
</a>
2323
{"\n"}
2424
</>

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ContainerReflection, DeclarationReflection, Reflection, ReflectionKind } from "../../../../models";
22
import { JSX, partition } from "../../../../utils";
33
import type { PageEvent } from "../../../events";
4-
import { camelToTitleCase, classNames, wbr } from "../../lib";
4+
import { camelToTitleCase, classNames, renderName, wbr } from "../../lib";
55
import type { DefaultThemeRenderContext } from "../DefaultThemeRenderContext";
66

77
export function navigation(context: DefaultThemeRenderContext, props: PageEvent<Reflection>) {
@@ -155,7 +155,7 @@ export function secondaryNavigation(context: DefaultThemeRenderContext, props: P
155155
>
156156
<a href={context.urlTo(child)} class="tsd-index-link">
157157
{context.icons[child.kind]()}
158-
{wbr(child.name)}
158+
{renderName(child)}
159159
</a>
160160
</li>
161161
);
@@ -183,7 +183,7 @@ export function secondaryNavigation(context: DefaultThemeRenderContext, props: P
183183
>
184184
<a href={context.urlTo(effectivePageParent)} class="tsd-index-link">
185185
{context.icons[effectivePageParent.kind]()}
186-
<span>{wbr(effectivePageParent.name)}</span>
186+
<span>{renderName(effectivePageParent)}</span>
187187
</a>
188188
{!!pageNavigation.length && <ul>{pageNavigation}</ul>}
189189
</li>

src/lib/output/themes/lib.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,18 @@ export function displayPartsToMarkdown(parts: CommentDisplayPart[], urlTo: Defau
157157

158158
return result.join("");
159159
}
160+
161+
/**
162+
* Renders the reflection name with an additional `?` if optional.
163+
*/
164+
export function renderName(refl: Reflection) {
165+
if (!refl.name) {
166+
return <em>{wbr(refl.kindString!)}</em>;
167+
}
168+
169+
if (refl.flags.isOptional) {
170+
return <>{wbr(refl.name)}?</>;
171+
}
172+
173+
return wbr(refl.name);
174+
}

0 commit comments

Comments
 (0)