question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Last signature is missing when multiple are defined

See original GitHub issue

Search terms

  • signature
  • missing

Expected Behavior

If I scan a method with multiple signatures, then I expect all of them to be present in the typedoc.json/reflection data.

Actual Behavior

The last one is always missing. I need that at least for the default value.

Steps to reproduce the bug

export class SignatureTest {
  /**
   * Test with multiple signatures.
   *
   * @param a The value to return.
   */
  multiSignature(a: boolean): boolean;
  multiSignature(a: number): number;
  multiSignature(a: unknown = 1): unknown {
    return a;
  }
}
typedoc.json
{
	"id": 0,
	"name": "@faker-js/faker",
	"kind": 1,
	"kindString": "Project",
	"flags": {},
	"originalName": "",
	"children": [
		{
			"id": 1,
			"name": "SignatureTest",
			"kind": 128,
			"kindString": "Class",
			"flags": {},
			"children": [
[...]
				{
					"id": 4,
					"name": "multiSignature",
					"kind": 2048,
					"kindString": "Method",
					"flags": {},
					"sources": [...]
					"signatures": [
						{
							"id": 5,
							"name": "multiSignature",
							"kind": 4096,
							"kindString": "Call signature",
							"flags": {},
							"comment": {
								"shortText": "Test with multiple signatures."
							},
							"parameters": [
								{
									"id": 6,
									"name": "a",
									"kind": 32768,
									"kindString": "Parameter",
									"flags": {},
									"comment": {
										"shortText": "The value to return.\n"
									},
									"type": {
										"type": "intrinsic",
										"name": "boolean"
									}
								}
							],
							"type": {
								"type": "intrinsic",
								"name": "boolean"
							}
						},
						{
							"id": 7,
							"name": "multiSignature",
							"kind": 4096,
							"kindString": "Call signature",
							"flags": {},
							"parameters": [
								{
									"id": 8,
									"name": "a",
									"kind": 32768,
									"kindString": "Parameter",
									"flags": {},
									"type": {
										"type": "intrinsic",
										"name": "number"
									}
								}
							],
							"type": {
								"type": "intrinsic",
								"name": "number"
							}
						},
+						{
+							"id": 9,
+							"name": "multiSignature",
+							"kind": 4096,
+							"kindString": "Call signature",
+							"flags": {},
+							"parameters": [
+								{
+									"id": 10,
+									"name": "a",
+									"kind": 32768,
+									"kindString": "Parameter",
+									"flags": {},
+									"type": {
+										"type": "intrinsic",
+										"name": "unknown"
+									},
+									"defaultValue": "1"
+								}
+							],
+							"type": {
+								"type": "intrinsic",
+								"name": "unknown"
+							}
+						}
					]
				}
			],
[...]
		}
	],
[...]
}

Environment

  • Typedoc version: ~0.22.12
  • TypeScript version: ~4.6.2
  • Node.js version: v16.14.0
  • OS: Windows 11
  • Related:
    • #1879 - Jsdocs comments only present on first signature

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
Gerrit0commented, Mar 19, 2022

What would be the best way to get the complete default value from the implementation signature?

That’s going to depend on what you mean by “complete”. Default values are an arbitrary expression, there’s no guarantee that they are a simple value… so it really depends on your use case. The simplest way to do this is, of course, to just get the text from the source file. This will put the default parameters in the JSON as strings from the source file, or null if a parameter doesn’t have a default value.

// typedoc --plugin path/to/this/file.js
const td = require("typedoc");

/** @param {td.Application} app */
exports.load = function (app) {
    app.converter.on(
        td.Converter.EVENT_CREATE_DECLARATION,
        /**
         * @param {td.Context} context
         * @param {td.Reflection} reflection
         */
        (context, reflection) => {
            const symbol = context.project.getSymbolFromReflection(reflection);
            if (!symbol) return;

            if (
                reflection.kindOf(td.ReflectionKind.Function | td.ReflectionKind.Method) &&
                (symbol.declarations?.length ?? 0) > 1
            ) {
                const lastDeclaration = symbol.declarations[symbol.declarations.length - 1];
                if (td.TypeScript.isFunctionLike(lastDeclaration)) {
                    reflection.implementationDefaultParameters = lastDeclaration.parameters.map(
                        (param) => param.initializer?.getText() || null
                    );
                    console.log(reflection.implementationDefaultParameters);
                }
            }
        }
    );

    // So that it shows up in JSON output
    app.serializer.addSerializer({
        serializeGroup(item) {
            return item instanceof td.Reflection;
        },
        supports(item) {
            return true;
        },
        toObject(refl, obj) {
            obj.implementationDefaultParameters = refl.implementationDefaultParameters;
            return obj;
        },
    });
};

0reactions
ST-DDTcommented, Mar 22, 2022

Thanks for this example. I added this to our project in https://github.com/faker-js/faker/pull/656

Read more comments on GitHub >

github_iconTop Results From Across the Web

MS Outlook signatures disappeared or missing after Office ...
I have lost access to all my previous signatures and when I try and recreate a signature with the same name, I am...
Read more >
TypeScript: Index signature is missing in type - Stack Overflow
The problem is that when the type is inferred, then the type of o is: { dic: { a: number, b: number }...
Read more >
Signatures are not added - CodeTwo
Another reason to why signatures are not added may be related to complex conditions defined for a particular rule. If you are adding...
Read more >
How do I Resolve the "At least one signature has problems ...
What does the error message mean? · The error message at the top of Adobe Reader says that something is wrong with the...
Read more >
Complying with Medicare Signature Requirements - CMS
How do we define a handwritten signature? ... If your signature is missing from the medical record (other than an order), send an...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found