Skip to content

Commit 30555f1

Browse files
committed
Fix comment discovery for @inheritDoc
Resolves #2087
1 parent ef598e7 commit 30555f1

File tree

4 files changed

+39
-0
lines changed

4 files changed

+39
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Unreleased
22

3+
### Bug Fixes
4+
5+
- Fixed comment discovery for `@inheritDoc` if inheriting from a function type alias, #2087.
6+
37
## v0.23.19 (2022-10-28)
48

59
### Bug Fixes

src/lib/converter/plugins/InheritDocPlugin.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
Comment,
33
DeclarationReflection,
44
ReflectionKind,
5+
ReflectionType,
56
SignatureReflection,
67
} from "../../models";
78
import { Component, ConverterComponent } from "../components";
@@ -105,6 +106,23 @@ export class InheritDocPlugin extends ConverterComponent {
105106
private copyComment(source: Reflection, target: Reflection) {
106107
if (!target.comment) return;
107108

109+
if (
110+
!source.comment &&
111+
source instanceof DeclarationReflection &&
112+
source.signatures
113+
) {
114+
source = source.signatures[0];
115+
}
116+
117+
if (
118+
!source.comment &&
119+
source instanceof DeclarationReflection &&
120+
source.type instanceof ReflectionType &&
121+
source.type.declaration.signatures
122+
) {
123+
source = source.type.declaration.signatures[0];
124+
}
125+
108126
if (!source.comment) {
109127
this.application.logger.warn(
110128
`${target.getFullName()} tried to copy a comment from ${source.getFullName()} with @inheritDoc, but the source has no associated comment.`
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/** Foo type comment */
2+
export type Foo = () => number;
3+
4+
export class Bar {
5+
/**
6+
* {@inheritDoc Foo:type}
7+
*/
8+
x = 1;
9+
}

src/test/issueTests.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,4 +817,12 @@ export const issueTests: {
817817
const sig = cap.signatures![0];
818818
equal(sig.type?.toString(), "Capitalize<T>");
819819
},
820+
821+
gh2087(project) {
822+
const x = query(project, "Bar.x");
823+
equal(
824+
Comment.combineDisplayParts(x.comment?.summary),
825+
"Foo type comment"
826+
);
827+
},
820828
};

0 commit comments

Comments
 (0)