Skip to content

Commit eea1c94

Browse files
authored
fix(theme): improve destructured parameters rendering and flatten lists (#167)
* fix(theme): improve destructured parameters rendering and flatten lists * chore: change the first char in interface to lowercase
1 parent c7aee7a commit eea1c94

2 files changed

Lines changed: 41 additions & 4 deletions

File tree

plugins/processor/index.mjs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,30 @@ export function load(app) {
3737
.getReflectionsByKind(ReflectionKind.Reference)
3838
.forEach(ref => context.project.removeReflection(ref));
3939

40+
// Destructured parameters are not supported by TypeDoc, so we rename them to
41+
// a more generic name.
42+
context.project
43+
.getReflectionsByKind(ReflectionKind.Parameter)
44+
.forEach(param => {
45+
if (param.name.startsWith('__namedParameters')) {
46+
if (
47+
param.type?.type === 'reflection' &&
48+
param.type.declaration?.children
49+
) {
50+
const destructuredKeys = param.type.declaration.children.map(
51+
child => child.name
52+
);
53+
param.name = `{ ${destructuredKeys.join(', ')} }`;
54+
} else if (param.type?.type === 'reference' && param.type.name) {
55+
const interfaceName = param.type.name;
56+
param.name =
57+
interfaceName[0].toLowerCase() + interfaceName.slice(1);
58+
} else {
59+
param.name = 'options';
60+
}
61+
}
62+
});
63+
4064
applyExportEqualsReflections(context.project);
4165
applySourceMetadata(context.project);
4266
});

plugins/theme/partials/index.mjs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,7 @@ export default ctx => {
5555
stability,
5656
stability && '',
5757
model.parameters?.length &&
58-
ctx.partials.parametersList(model.parameters, {
59-
headingLevel: options.headingLevel,
60-
}),
58+
ctx.partials.parametersList(model.parameters),
6159
ctx.helpers.typedListItem({
6260
label: 'Returns',
6361
type: model.type ?? 'void',
@@ -301,7 +299,22 @@ export default ctx => {
301299

302300
memberTitle: model =>
303301
getMemberTitle(model, { local: isTypePage(ctx.page.model) }),
304-
parametersList: ctx.helpers.typedList,
302+
parametersList(parameters) {
303+
const flatList = [];
304+
305+
parameters.forEach(param => {
306+
if (
307+
param.type?.type === 'reflection' &&
308+
param.type.declaration?.children
309+
) {
310+
flatList.push(...param.type.declaration.children);
311+
} else {
312+
flatList.push(param);
313+
}
314+
});
315+
316+
return ctx.helpers.typedList(flatList);
317+
},
305318
typeDeclarationList: ctx.helpers.typedList,
306319
propertiesTable: ctx.helpers.typedList,
307320

0 commit comments

Comments
 (0)