Skip to content

Commit 02ff118

Browse files
authored
[docs-infra] Make it possible to override the displayed type in API reference (#1884)
1 parent e5991bf commit 02ff118

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

scripts/api-docs-builder/src/formatter.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export function formatProperties(props: rae.PropertyNode[]) {
66

77
for (const prop of props) {
88
result[prop.name] = {
9-
type: formatType(prop.type, prop.optional),
9+
type: formatType(prop.type, prop.optional, prop.documentation?.tags),
1010
default: prop.documentation?.defaultValue,
1111
required: !prop.optional || undefined,
1212
description: prop.documentation?.description,
@@ -21,7 +21,7 @@ export function formatParameters(params: rae.Parameter[]) {
2121

2222
for (const param of params) {
2323
result[param.name] = {
24-
type: formatType(param.type, param.optional, true),
24+
type: formatType(param.type, param.optional, param.documentation?.tags, true),
2525
default: param.defaultValue,
2626
optional: param.optional || undefined,
2727
description: param.documentation?.description,
@@ -46,8 +46,16 @@ export function formatEnum(enumNode: rae.EnumNode) {
4646
export function formatType(
4747
type: rae.TypeNode,
4848
removeUndefined: boolean,
49+
jsdocTags: rae.DocumentationTag[] | undefined = undefined,
4950
expandObjects: boolean = false,
5051
): string {
52+
const typeTag = jsdocTags?.find((tag) => tag.name === 'type');
53+
const typeValue = typeTag?.value;
54+
55+
if (typeValue) {
56+
return typeValue;
57+
}
58+
5159
if (type instanceof rae.ReferenceNode) {
5260
if (/^ReactElement(<.*>)?/.test(type.name)) {
5361
return 'ReactElement';

0 commit comments

Comments
 (0)