Skip to content

Commit 9b586db

Browse files
fix: copy inherited parameter descriptions (#1303)
Original change by @kayahr in #788 but was deleted before the pull request could be merged. Fixes #787
1 parent 8edb17c commit 9b586db

File tree

3 files changed

+469
-2
lines changed

3 files changed

+469
-2
lines changed

src/lib/converter/plugins/ImplementsPlugin.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Type, ReferenceType } from '../../models/types/index';
33
import { Component, ConverterComponent } from '../components';
44
import { Converter } from '../converter';
55
import { Context } from '../context';
6+
import { Comment } from '../../models/comments/comment';
67

78
/**
89
* A plugin that detects interface implementations of functions and
@@ -88,8 +89,13 @@ export class ImplementsPlugin extends ConverterComponent {
8889
if (target instanceof SignatureReflection && target.parameters &&
8990
source instanceof SignatureReflection && source.parameters) {
9091
for (let index = 0, count = target.parameters.length; index < count; index++) {
91-
if (target.parameters[index].comment) {
92-
target.parameters[index].comment!.copyFrom(source.parameters[index].comment!);
92+
const sourceParameter = source.parameters[index];
93+
if (sourceParameter && sourceParameter.comment) {
94+
const targetParameter = target.parameters[index];
95+
if (!targetParameter.comment) {
96+
targetParameter.comment = new Comment();
97+
targetParameter.comment.copyFrom(sourceParameter.comment);
98+
}
9399
}
94100
}
95101
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
export interface Base {
2+
/**
3+
* @param a - Parameter A.
4+
* @param b - Parameter B.
5+
*/
6+
method1(a: number, b: string): void;
7+
}
8+
9+
export class Class1 implements Base {
10+
/** @inheritDoc */
11+
method1(a: number, b: string): void {}
12+
}
13+
14+
export class Class2 implements Base {
15+
/**
16+
* @inheritDoc
17+
*
18+
* @param a - Custom parameter A doc.
19+
*/
20+
method1(a: number, b: string): void {}
21+
}
22+
23+
export class Class3 implements Base {
24+
/**
25+
* @inheritDoc
26+
*
27+
* @param c - Custom second parameter doc with name change.
28+
*/
29+
method1(a: number, c: string): void {}
30+
}

0 commit comments

Comments
 (0)