Skip to content

Commit 634163e

Browse files
devversionmmalerba
authored andcommitted
docs: properly show method overloads (#12308)
* Shows method overloads in the documentation instead of showing the overload-base method that has most likely no `JSDoc` nor good-explaining parameter names (parameters have multiple purposes and types)
1 parent 436981a commit 634163e

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

tools/dgeni/processors/categorizer.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export class Categorizer implements Processor {
4949
// Special decorations for real class documents that don't apply for interfaces.
5050
if (classLikeDoc.docType === 'class') {
5151
this.decorateClassDoc(classLikeDoc as CategorizedClassDoc);
52+
this.replaceMethodsWithOverload(classLikeDoc as CategorizedClassDoc);
5253
}
5354

5455
// Call decorate hooks that can modify the method and property docs.
@@ -117,6 +118,29 @@ export class Categorizer implements Processor {
117118
propertyDoc.isDirectiveOutput = !!outputMetadata;
118119
propertyDoc.directiveOutputAlias = (outputMetadata && outputMetadata.alias) || '';
119120
}
121+
122+
/**
123+
* Walks through every method of the specified class doc and replaces the method
124+
* with its referenced overload method definitions, if the method is having overload definitions.
125+
*/
126+
private replaceMethodsWithOverload(classDoc: CategorizedClassDoc) {
127+
const methodsToAdd: CategorizedMethodMemberDoc[] = [];
128+
129+
classDoc.methods.forEach((methodDoc, index) => {
130+
if (methodDoc.overloads.length > 0) {
131+
132+
// Add each method overload to the methods that will be shown in the docs.
133+
// Note that we cannot add the overloads immediately to the methods array because
134+
// that would cause the iteration to visit the new overloads.
135+
methodsToAdd.push(...methodDoc.overloads as CategorizedMethodMemberDoc[]);
136+
137+
// Remove the base method for the overloads from the documentation.
138+
classDoc.methods.splice(index, 1);
139+
}
140+
});
141+
142+
classDoc.methods.push(...methodsToAdd);
143+
}
120144
}
121145

122146
/** Filters any duplicate classDoc members from an array */

0 commit comments

Comments
 (0)