Skip to content

Commit

Permalink
Fix usage of @typeParam on type aliases
Browse files Browse the repository at this point in the history
Resolves #1733
  • Loading branch information
Gerrit0 committed Oct 10, 2021
1 parent 244e904 commit d6fc617
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 29 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,7 @@

- Fixed flash when navigating to a second page when OS theme does not match selected theme, #1709.
- Fixed improper quoting of `as const` style enums, #1727.
- Fixed handling of `@typeParam` on type aliases, #1733.

### Thanks!

Expand Down
7 changes: 5 additions & 2 deletions src/lib/converter/symbols.ts
Expand Up @@ -302,11 +302,14 @@ function convertTypeAlias(
declaration.type
);

context.finalizeDeclarationReflection(reflection, symbol, exportSymbol);

// Do this after finalization so that the CommentPlugin can get @typeParam tags
// from the parent comment. Ugly, but works for now. Should be cleaned up with TSDoc
// support.
reflection.typeParameters = declaration.typeParameters?.map((param) =>
createTypeParamReflection(param, context.withScope(reflection))
);

context.finalizeDeclarationReflection(reflection, symbol, exportSymbol);
} else if (
ts.isJSDocTypedefTag(declaration) ||
ts.isJSDocEnumTag(declaration)
Expand Down
20 changes: 2 additions & 18 deletions src/lib/models/ReflectionCategory.ts
Expand Up @@ -18,35 +18,19 @@ export class ReflectionCategory {
*/
children: Reflection[] = [];

/**
* Do all children of this category have a separate document?
*
* A bound representation of the ´ReflectionCategory.getAllChildrenHaveOwnDocument´
* that can be used within templates.
*/
allChildrenHaveOwnDocument: Function;

/**
* Create a new ReflectionCategory instance.
*
* @param title The title of this category.
*/
constructor(title: string) {
this.title = title;

this.allChildrenHaveOwnDocument = () =>
this.getAllChildrenHaveOwnDocument();
}

/**
* Do all children of this category have a separate document?
*/
private getAllChildrenHaveOwnDocument(): boolean {
let onlyOwnDocuments = true;
this.children.forEach((child) => {
onlyOwnDocuments = onlyOwnDocuments && !!child.hasOwnDocument;
});

return onlyOwnDocuments;
allChildrenHaveOwnDocument(): boolean {
return this.children.every((child) => child.hasOwnDocument);
}
}
10 changes: 1 addition & 9 deletions src/lib/models/ReflectionGroup.ts
Expand Up @@ -30,14 +30,6 @@ export class ReflectionGroup {
*/
cssClasses?: string;

/**
* Do all children of this group have a separate document?
*
* A bound representation of the ´ReflectionGroup.getAllChildrenHaveOwnDocument´
* that can be used within templates.
*/
allChildrenHaveOwnDocument = () => this.getAllChildrenHaveOwnDocument();

/**
* Are all children inherited members?
*/
Expand Down Expand Up @@ -77,7 +69,7 @@ export class ReflectionGroup {
/**
* Do all children of this group have a separate document?
*/
private getAllChildrenHaveOwnDocument(): boolean {
allChildrenHaveOwnDocument(): boolean {
return this.children.every((child) => child.hasOwnDocument);
}
}
9 changes: 9 additions & 0 deletions src/test/converter2/issues/gh1733.ts
@@ -0,0 +1,9 @@
/**
* @typeParam T T docs
*/
export type Foo<T> = T;

/**
* @typeParam T T docs
*/
export class Bar<T> {}
7 changes: 7 additions & 0 deletions src/test/issueTests.ts
Expand Up @@ -235,4 +235,11 @@ export const issueTests: {
ok(alias.type instanceof QueryType);
equal(alias.type.queryType.name, "m.SomeClass.someProp");
},

gh1733(project) {
const alias = query(project, "Foo");
equal(alias.typeParameters?.[0].comment?.shortText.trim(), "T docs");
const cls = query(project, "Bar");
equal(cls.typeParameters?.[0].comment?.shortText.trim(), "T docs");
},
};

0 comments on commit d6fc617

Please sign in to comment.