Skip to content

Commit

Permalink
Fix comment discovery for @inheritDoc
Browse files Browse the repository at this point in the history
Resolves #2087
  • Loading branch information
Gerrit0 committed Oct 29, 2022
1 parent ef598e7 commit 30555f1
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,9 @@
# Unreleased

### Bug Fixes

- Fixed comment discovery for `@inheritDoc` if inheriting from a function type alias, #2087.

## v0.23.19 (2022-10-28)

### Bug Fixes
Expand Down
18 changes: 18 additions & 0 deletions src/lib/converter/plugins/InheritDocPlugin.ts
Expand Up @@ -2,6 +2,7 @@ import {
Comment,
DeclarationReflection,
ReflectionKind,
ReflectionType,
SignatureReflection,
} from "../../models";
import { Component, ConverterComponent } from "../components";
Expand Down Expand Up @@ -105,6 +106,23 @@ export class InheritDocPlugin extends ConverterComponent {
private copyComment(source: Reflection, target: Reflection) {
if (!target.comment) return;

if (
!source.comment &&
source instanceof DeclarationReflection &&
source.signatures
) {
source = source.signatures[0];
}

if (
!source.comment &&
source instanceof DeclarationReflection &&
source.type instanceof ReflectionType &&
source.type.declaration.signatures
) {
source = source.type.declaration.signatures[0];
}

if (!source.comment) {
this.application.logger.warn(
`${target.getFullName()} tried to copy a comment from ${source.getFullName()} with @inheritDoc, but the source has no associated comment.`
Expand Down
9 changes: 9 additions & 0 deletions src/test/converter2/issues/gh2087.ts
@@ -0,0 +1,9 @@
/** Foo type comment */
export type Foo = () => number;

export class Bar {
/**
* {@inheritDoc Foo:type}
*/
x = 1;
}
8 changes: 8 additions & 0 deletions src/test/issueTests.ts
Expand Up @@ -817,4 +817,12 @@ export const issueTests: {
const sig = cap.signatures![0];
equal(sig.type?.toString(), "Capitalize<T>");
},

gh2087(project) {
const x = query(project, "Bar.x");
equal(
Comment.combineDisplayParts(x.comment?.summary),
"Foo type comment"
);
},
};

0 comments on commit 30555f1

Please sign in to comment.