typedoc icon indicating copy to clipboard operation
typedoc copied to clipboard

Better documetation of Overloading types

Open adamjosefus opened this issue 3 years ago • 1 comments

Problem

If you are using overloading type in your functions/methods, the builder documentation is not really helpful in this task.

Code Example A:

type Entry =
    | [title: string, content: string, button: string]
    | [title: string, content: string, button: string, options: Options]
    | [title: string, content: string, primary: string, secondary: string, options: Options];

function myFunction(...entry: Entry): void {
    // Some code...
}

VS Code intellisense: Snímek obrazovky 2022-07-13 v 19 53 52 Snímek obrazovky 2022-07-13 v 19 53 52

Code Example B:

function myFunction(param1: string): void;
function myFunction(param1: number, param2: boolean): void;

function myFunction(param1: string | number, param2?: boolean): void {
    // Some code...
}

VS Code intellisense: Snímek obrazovky 2022-07-13 v 19 50 14 Snímek obrazovky 2022-07-13 v 19 50 22

Suggested Solution

  • Detect type for overloading and include it next to the function.
  • Render all argument possibilities

adamjosefus avatar Jul 13 '22 18:07 adamjosefus

This is going to be a tricky one I think... should be possible, but by no means trivial.

Gerrit0 avatar Jul 17 '22 19:07 Gerrit0

The language service is entirely too magical... and inconsistent. When hovering over the function, it shows "real" overloads...

image

But when providing arguments, it instead shows "signatures"

image

I think I'm actually going to punt this to plugin-space. I'm really wary of including functionality in TypeDoc itself which significantly changes what you'd see if looking at the declaration file of a library, since it opens up holes for questions when there's now no reference to Entry in the docs for myFunction, or myFunction is rendered with Entry and then also with the expanded signatures (ew, makes it looks like there's an extra overload...)

I might consider this if someone builds a plugin which does this that solves these issues in the rendered docs, but I'm not seeing a clean way of doing it.


If looking to implement this without solving that issue, I'd recommend listening to Converter.EVENT_CREATE_SIGNATURE and replacing sig.parent.signatures with the appropriately expanded signatures. I've just updated the emit for that event to also include the signature, which will be necessary to easily resolve parameter types.

Gerrit0 avatar Dec 18 '22 03:12 Gerrit0