Skip to content

Commit

Permalink
Any call signature will result in a variable being a function
Browse files Browse the repository at this point in the history
Closes #1651
  • Loading branch information
Gerrit0 committed Jul 1, 2022
1 parent 3622a81 commit e74eea6
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -8,6 +8,7 @@
- `intentionallyNotExported` will now properly respect qualified names, #1972.
- Fixed missing namespace comments on `export * as NS` declarations, #1973.
- Fixed missing comments on `export const x = () => 123` function variables, #1973.
- Exported variable functions with properties will now be converted as a function+namespace instead of a variable+namespace, #1651.
- Validation warnings caused by missing documentation will now be formatted like other warnings which reference a declaration.
- TypeDoc will no longer warn if both the `get` and `set` signatures of an accessor have a comment.

Expand Down
1 change: 1 addition & 0 deletions src/lib/converter/comments/discovery.ts
Expand Up @@ -32,6 +32,7 @@ const wantedKinds: Record<ReflectionKind, ts.SyntaxKind[]> = {
ts.SyntaxKind.VariableDeclaration,
ts.SyntaxKind.BindingElement,
ts.SyntaxKind.ExportAssignment,
ts.SyntaxKind.PropertyAccessExpression,
],
[ReflectionKind.Function]: [
ts.SyntaxKind.FunctionDeclaration,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/converter/symbols.ts
Expand Up @@ -788,7 +788,7 @@ function convertVariable(
return convertVariableAsEnum(context, symbol, exportSymbol);
}

if (type.getCallSignatures().length && !type.getProperties().length) {
if (type.getCallSignatures().length) {
return convertVariableAsFunction(context, symbol, exportSymbol);
}

Expand Down
6 changes: 6 additions & 0 deletions src/test/converter2/issues/gh1651.ts
@@ -0,0 +1,6 @@
/** bar */
export const bar = () => {};
/** metadata */
bar.metadata = "baz";
/** fn */
bar.fn = () => {};
21 changes: 21 additions & 0 deletions src/test/issueTests.ts
Expand Up @@ -294,6 +294,27 @@ export const issueTests: {
equal(ctor.sources?.[0]?.character, 4);
},

gh1651(project) {
equal(
project.children?.map((c) => c.name),
["bar", "bar"]
);

equal(
project.children[0].children?.map((c) => c.name),
["metadata", "fn"]
);

const comments = [
project.children[0].comment?.summary,
project.children[0].children[0].comment?.summary,
project.children[0].children[1].signatures![0].comment?.summary,
project.children[1].signatures![0].comment?.summary,
].map(Comment.combineDisplayParts);

equal(comments, ["", "metadata", "fn", "bar"]);
},

gh1660(project) {
const alias = query(project, "SomeType");
ok(alias.type instanceof QueryType);
Expand Down

0 comments on commit e74eea6

Please sign in to comment.