Skip to content

Commit aa36d85

Browse files
committed
Add support for TypeScript 5's @overload
Ref: #2201
1 parent 642dd2e commit aa36d85

File tree

7 files changed

+72
-8
lines changed

7 files changed

+72
-8
lines changed

src/lib/converter/comments/discovery.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { ReflectionKind } from "../../models";
33
import { assertNever, Logger } from "../../utils";
44
import { CommentStyle } from "../../utils/options/declaration";
55
import { nicePath } from "../../utils/paths";
6+
import { ok } from "assert";
67

78
// Note: This does NOT include JSDoc syntax kinds. This is important!
89
// Comments from @typedef and @callback tags are handled specially by
@@ -172,6 +173,22 @@ export function discoverSignatureComment(
172173
return;
173174
}
174175

176+
if (ts.isJSDocSignature(node)) {
177+
const comment = node.parent.parent;
178+
ok(ts.isJSDoc(comment));
179+
180+
return [
181+
node.getSourceFile(),
182+
[
183+
{
184+
kind: ts.SyntaxKind.MultiLineCommentTrivia,
185+
pos: comment.pos,
186+
end: comment.end,
187+
},
188+
],
189+
];
190+
}
191+
175192
const text = node.getSourceFile().text;
176193

177194
const comments = collectCommentRanges(

src/lib/converter/symbols.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -422,13 +422,8 @@ function convertFunctionOrMethod(
422422

423423
// Can't use zip here. We might have less declarations than signatures
424424
// or less signatures than declarations.
425-
for (let i = 0; i < signatures.length; i++) {
426-
createSignature(
427-
scope,
428-
ReflectionKind.CallSignature,
429-
signatures[i],
430-
declarations[i]
431-
);
425+
for (const sig of signatures) {
426+
createSignature(scope, ReflectionKind.CallSignature, sig);
432427
}
433428
}
434429

src/lib/utils/options/sources/typedoc.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,12 @@ export function addTypeDocOptions(options: Pick<Options, "addDeclaration">) {
301301
name: "excludeTags",
302302
help: "Remove the listed block/modifier tags from doc comments.",
303303
type: ParameterType.Array,
304-
defaultValue: ["@override", "@virtual", "@privateRemarks"],
304+
defaultValue: [
305+
"@override",
306+
"@virtual",
307+
"@privateRemarks",
308+
"@satisfies",
309+
],
305310
validate(value) {
306311
if (!Validation.validate([Array, Validation.isTagString], value)) {
307312
throw new Error(

src/lib/utils/options/tsdoc-defaults.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export const blockTags = [
2525
"@callback",
2626
"@prop",
2727
"@property",
28+
"@satisfies",
2829
] as const;
2930

3031
export const tsdocInlineTags = ["@link", "@inheritDoc", "@label"] as const;
@@ -52,4 +53,5 @@ export const modifierTags = [
5253
"@ignore",
5354
"@enum",
5455
"@event",
56+
"@overload",
5557
] as const;

src/test/behaviorTests.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,25 @@ export const behaviorTests: {
577577
logger.expectNoOtherMessages();
578578
},
579579

580+
overloadTags(project) {
581+
const printValue = query(project, "printValue");
582+
equal(printValue.signatures?.length, 2);
583+
584+
const [first, second] = printValue.signatures;
585+
586+
equal(first.parameters?.length, 1);
587+
equal(
588+
Comment.combineDisplayParts(first.parameters[0].comment?.summary),
589+
"first docs"
590+
);
591+
592+
equal(second.parameters?.length, 2);
593+
equal(
594+
Comment.combineDisplayParts(second.parameters[0].comment?.summary),
595+
"second docs"
596+
);
597+
},
598+
580599
readonlyTag(project) {
581600
const title = query(project, "Book.title");
582601
const author = query(project, "Book.author");
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* @overload
3+
* @param {string} value first docs
4+
* @return {void}
5+
*/
6+
7+
/**
8+
* @overload
9+
* @param {number} value second docs
10+
* @param {number} [maximumFractionDigits] second docs
11+
* @return {void}
12+
*/
13+
14+
/**
15+
* @param {string | number} value impl docs
16+
* @param {number} [maximumFractionDigits] impl docs
17+
*/
18+
export function printValue(value, maximumFractionDigits) {}

tsdoc.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,14 @@
7474
{
7575
"tagName": "@protected",
7676
"syntaxKind": "modifier"
77+
},
78+
{
79+
"tagName": "@satisfies",
80+
"syntaxKind": "block"
81+
},
82+
{
83+
"tagName": "@overload",
84+
"syntaxKind": "modifier"
7785
}
7886
]
7987
}

0 commit comments

Comments
 (0)