From 6d92e84b8a366d443294330ac02dba225ea943ee Mon Sep 17 00:00:00 2001 From: Gerrit Birkeland Date: Mon, 29 May 2023 16:03:49 -0600 Subject: [PATCH] Render objects one level deep Resolves #2276 --- CHANGELOG.md | 1 + .../default/partials/member.declaration.tsx | 81 +++++++++++-------- 2 files changed, 49 insertions(+), 33 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ae0c13a2..a5e4176d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - TypeDoc's `--pretty` option now also controls whether generated HTML contains line breaks, #2287. - Optimized icon caching to reduce file size in generated HTML documentation, #2287. +- Render property description of "roughly top level" object types, #2276. - Added `MarkdownEvent.INCLUDE` for plugins, #2284. ### Bug Fixes diff --git a/src/lib/output/themes/default/partials/member.declaration.tsx b/src/lib/output/themes/default/partials/member.declaration.tsx index 360e7c81b..7ed7ce935 100644 --- a/src/lib/output/themes/default/partials/member.declaration.tsx +++ b/src/lib/output/themes/default/partials/member.declaration.tsx @@ -1,42 +1,57 @@ -import { DeclarationReflection, ReflectionType } from "../../../../models"; +import type { DeclarationReflection, ReflectionType } from "../../../../models"; import { JSX } from "../../../../utils"; import { getKindClass, hasTypeParameters, renderTypeParametersSignature, wbr } from "../../lib"; import type { DefaultThemeRenderContext } from "../DefaultThemeRenderContext"; -export const memberDeclaration = (context: DefaultThemeRenderContext, props: DeclarationReflection) => ( - <> -
- {wbr(props.name)} - {renderTypeParametersSignature(context, props.typeParameters)} - {props.type && ( - <> - {!!props.flags.isOptional && "?"}:{" "} - {context.type(props.type)} - - )} - {!!props.defaultValue && ( - <> - - {" = "} - {props.defaultValue} - - - )} -
- - {context.commentSummary(props)} - - {hasTypeParameters(props) && context.typeParameters(props.typeParameters)} - - {props.type instanceof ReflectionType && ( +export function memberDeclaration(context: DefaultThemeRenderContext, props: DeclarationReflection) { + function renderTypeDeclaration(type: ReflectionType) { + return (

Type declaration

- {context.parameter(props.type.declaration)} + {context.parameter(type.declaration)}
- )} + ); + } - {context.commentTags(props)} + const visitor = { reflection: renderTypeDeclaration }; - {context.memberSources(props)} - -); + return ( + <> +
+ {wbr(props.name)} + {renderTypeParametersSignature(context, props.typeParameters)} + {props.type && ( + <> + {!!props.flags.isOptional && "?"}:{" "} + {context.type(props.type)} + + )} + {!!props.defaultValue && ( + <> + + {" = "} + {props.defaultValue} + + + )} +
+ + {context.commentSummary(props)} + + {hasTypeParameters(props) && context.typeParameters(props.typeParameters)} + + {props.type?.visit({ + reflection: renderTypeDeclaration, + array: (arr) => arr.elementType.visit(visitor), + intersection: (int) => int.types.map((t) => t.visit(visitor)), + union: (union) => union.types.map((t) => t.visit(visitor)), + reference: (ref) => ref.typeArguments?.map((t) => t.visit(visitor)), + tuple: (ref) => ref.elements.map((t) => t.visit(visitor)), + })} + + {context.commentTags(props)} + + {context.memberSources(props)} + + ); +}