Links to specific overloads of functions #2980
-
Is there a way in typedoc to link to a specific method overload? I would like to reference a specific method overload in the documentation. Adding the signature to the link does not work: {@link MyClass.myMethod(string,number) | myMethod overload} given these typings: class MyClass {
myMethod(a: string, b: number): void
myMethod(a: string, b: boolean): void
} I'm mostly interested in the json output. I can probably fix the links after typedoc has generated the json, since signatures also have IDs. I can probably just change the id of the link target. Is there a native way to do that without postprocessing? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
See https://typedoc.org/documents/Declaration_References.html#meaning |
Beta Was this translation helpful? Give feedback.
This comment was marked as spam.
This comment was marked as spam.
-
Thank you for your response. I've tried all variants but none of them seem to resolve the overload correctly. Given these types: export class MyClass {
/**
* {@link myMethod:0 | myMethodFirstOverload}
* {@link myMethod:0}
* {@link myMethod:1}
* {@link myMethod:(0)}
* {@link myMethod:(1)}
* {@link myMethod:member(0)}
* {@link myMethod:member(1)}
* {@link myMethod:STRING_NUMBER}
* {@link myMethod:STRING_BOOLEAN}
*/
link: never
/**
* string-number
* {@label STRING_NUMBER}
*/
myMethod(a: string, b: number): void
/**
* string-boolean
* {@label STRING_BOOLEAN}
*/
myMethod(a: string, b: boolean):void
} the json output looks like this: ...
{
"id": 6,
"name": "link",
"variant": "declaration",
"kind": 1024,
"flags": {},
"comment": {
"summary": [
{
"kind": "inline-tag",
"tag": "@link",
"text": ":0 | myMethodFirstOverload",
"target": 7,
"tsLinkText": ":0 | myMethodFirstOverload"
},
{
"kind": "text",
"text": "\n"
},
{
"kind": "inline-tag",
"tag": "@link",
"text": ":0",
"target": 7,
"tsLinkText": ":0"
},
{
"kind": "text",
"text": "\n"
},
{
"kind": "inline-tag",
"tag": "@link",
"text": ":1",
"target": 7,
"tsLinkText": ":1"
},
{
"kind": "text",
"text": "\n"
},
{
"kind": "inline-tag",
"tag": "@link",
"text": ":(0)",
"target": 7,
"tsLinkText": ":(0)"
},
{
"kind": "text",
"text": "\n"
},
{
"kind": "inline-tag",
"tag": "@link",
"text": ":(1)",
"target": 7,
"tsLinkText": ":(1)"
},
{
"kind": "text",
"text": "\n"
},
{
"kind": "inline-tag",
"tag": "@link",
"text": ":member(0)",
"target": 7,
"tsLinkText": ":member(0)"
},
{
"kind": "text",
"text": "\n"
},
{
"kind": "inline-tag",
"tag": "@link",
"text": ":member(1)",
"target": 7,
"tsLinkText": ":member(1)"
},
{
"kind": "text",
"text": "\n"
},
{
"kind": "inline-tag",
"tag": "@link",
"text": ":STRING_NUMBER",
"target": 7,
"tsLinkText": ":STRING_NUMBER"
},
{
"kind": "text",
"text": "\n"
},
{
"kind": "inline-tag",
"tag": "@link",
"text": ":STRING_BOOLEAN",
"target": 7,
"tsLinkText": ":STRING_BOOLEAN"
}
]
},
"type": {
"type": "intrinsic",
"name": "never"
}
},
{
"id": 7,
"name": "myMethod",
"variant": "declaration",
"kind": 2048,
"flags": {},
"signatures": [
{
"id": 8,
"name": "myMethod",
"variant": "signature",
"kind": 4096,
"flags": {},
"comment": {
"summary": [
{
"kind": "text",
"text": "string-number\n"
}
],
"label": "STRING_NUMBER"
},
"parameters": [
{
"id": 9,
"name": "a",
"variant": "param",
"kind": 32768,
"flags": {},
"type": {
"type": "intrinsic",
"name": "string"
}
},
{
"id": 10,
"name": "b",
"variant": "param",
"kind": 32768,
"flags": {},
"type": {
"type": "intrinsic",
"name": "number"
}
}
],
"type": {
"type": "intrinsic",
"name": "void"
}
},
{
"id": 11,
"name": "myMethod",
"variant": "signature",
"kind": 4096,
"flags": {},
"comment": {
"summary": [
{
"kind": "text",
"text": "string-boolean\n"
}
],
"label": "STRING_BOOLEAN"
},
"parameters": [
{
"id": 12,
"name": "a",
"variant": "param",
"kind": 32768,
"flags": {},
"type": {
"type": "intrinsic",
"name": "string"
}
},
{
"id": 13,
"name": "b",
"variant": "param",
"kind": 32768,
"flags": {},
"type": {
"type": "intrinsic",
"name": "boolean"
}
}
],
"type": {
"type": "intrinsic",
"name": "void"
}
}
]
}
... All links link to the same id (7), which is the id of the method with all overloads, not of a specific overload. It looks like only the part before the colon ":" is parsed to resolve the link. The rest seems to end up in the link text. EDIT: I'm using the latest 0.28.7 release. |
Beta Was this translation helpful? Give feedback.
-
I've now discovered you need to turn off TypeScript link resolution: "typedocOptions": {
"useTsLinkResolution": false,
} Then links to overloads work like described in https://typedoc.org/documents/Declaration_References.html#declaration-references. |
Beta Was this translation helpful? Give feedback.
I've now discovered you need to turn off TypeScript link resolution:
Then links to overloads work like described in https://typedoc.org/documents/Declaration_References.html#declaration-references.