Skip to content
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

fix: copy inherited parameter descriptions #1303

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/lib/converter/plugins/ImplementsPlugin.ts
Expand Up @@ -3,6 +3,7 @@ import { Type, ReferenceType } from '../../models/types/index';
import { Component, ConverterComponent } from '../components';
import { Converter } from '../converter';
import { Context } from '../context';
import { Comment } from '../../models/comments/comment';

/**
* A plugin that detects interface implementations of functions and
Expand Down Expand Up @@ -88,8 +89,13 @@ export class ImplementsPlugin extends ConverterComponent {
if (target instanceof SignatureReflection && target.parameters &&
source instanceof SignatureReflection && source.parameters) {
for (let index = 0, count = target.parameters.length; index < count; index++) {
if (target.parameters[index].comment) {
target.parameters[index].comment!.copyFrom(source.parameters[index].comment!);
const sourceParameter = source.parameters[index];
if (sourceParameter && sourceParameter.comment) {
const targetParameter = target.parameters[index];
if (!targetParameter.comment) {
targetParameter.comment = new Comment();
targetParameter.comment.copyFrom(sourceParameter.comment);
}
}
}
}
Expand Down
30 changes: 30 additions & 0 deletions src/test/converter/inherit-param-doc/inherit-param-doc.ts
@@ -0,0 +1,30 @@
export interface Base {
/**
* @param a - Parameter A.
* @param b - Parameter B.
*/
method1(a: number, b: string): void;
}

export class Class1 implements Base {
/** @inheritDoc */
method1(a: number, b: string): void {}
}

export class Class2 implements Base {
/**
* @inheritDoc
*
* @param a - Custom parameter A doc.
*/
method1(a: number, b: string): void {}
}

export class Class3 implements Base {
/**
* @inheritDoc
*
* @param c - Custom second parameter doc with name change.
*/
method1(a: number, c: string): void {}
}