Skip to content

docs: properly show method overloads #12308

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 24, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions tools/dgeni/processors/categorizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export class Categorizer implements Processor {
// Special decorations for real class documents that don't apply for interfaces.
if (classLikeDoc.docType === 'class') {
this.decorateClassDoc(classLikeDoc as CategorizedClassDoc);
this.replaceMethodsWithOverload(classLikeDoc as CategorizedClassDoc);
}

// Call decorate hooks that can modify the method and property docs.
Expand Down Expand Up @@ -117,6 +118,29 @@ export class Categorizer implements Processor {
propertyDoc.isDirectiveOutput = !!outputMetadata;
propertyDoc.directiveOutputAlias = (outputMetadata && outputMetadata.alias) || '';
}

/**
* Walks through every method of the specified class doc and replaces the method
* with its referenced overload method definitions, if the method is having overload definitions.
*/
private replaceMethodsWithOverload(classDoc: CategorizedClassDoc) {
const methodsToAdd: CategorizedMethodMemberDoc[] = [];

classDoc.methods.forEach((methodDoc, index) => {
if (methodDoc.overloads.length > 0) {

// Add each method overload to the methods that will be shown in the docs.
// Note that we cannot add the overloads immediately to the methods array because
// that would cause the iteration to visit the new overloads.
methodsToAdd.push(...methodDoc.overloads as CategorizedMethodMemberDoc[]);

// Remove the base method for the overloads from the documentation.
classDoc.methods.splice(index, 1);
}
});

classDoc.methods.push(...methodsToAdd);
}
}

/** Filters any duplicate classDoc members from an array */
Expand Down