-
-
Notifications
You must be signed in to change notification settings - Fork 735
Last signature is missing when multiple are defined #1878
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This is working as expected. The implementation signature is not visible to consumers of the function and is therefore not included in the documentation. You could create a plugin which extracts the information you need at conversion time. const td = require("typedoc")
exports.load = function(app) {
app.converter.on(td.Converter.EVENT_CREATE_DECLARATION, (context, reflection) => {
// getSymbolFromReflection is marked @internal, in the next version with breaking changes
// the symbol should be passed in to this listener so it shouldn't be necessary here
const symbol = context.project.getSymbolFromReflection(reflection);
if (!symbol) return;
if (reflection.kindOf(td.ReflectionKind.Function | td.ReflectionKind.Method)) {
console.log(symbol.declarations?.map(d => d.getText()))
}
});
} |
What would be the best way to get the complete default value from the implementation signature? |
Has this issue been fixed? |
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 // 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;
},
});
}; |
Thanks for this example. |
Uh oh!
There was an error while loading. Please reload this page.
Search terms
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
typedoc.json
Environment
~0.22.12
~4.6.2
v16.14.0
Windows 11
The text was updated successfully, but these errors were encountered: