-
-
Notifications
You must be signed in to change notification settings - Fork 734
Typedoc seems not to read through keyof
another type
#1894
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
It's also quite possible that I just have no idea how this thing is supposed to work, rather that that this is a bug. |
Possibly related to #1519, in that I'd love for Typedoc to actually resolve |
This is working as intended - it's a different feature request than 1519, closer to #1823. I don't think this is something that it makes sense for TypeDoc to do by default. Expanding // 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, resolveKeyof);
};
/**
* @param {td.Context} context
* @param {td.DeclarationReflection} reflection
* @param {td.TypeScript.Node | undefined} node
*/
function resolveKeyof(context, reflection, node) {
if (!node) return;
if (
reflection.kindOf(td.ReflectionKind.TypeAlias) &&
reflection.type?.type === "typeOperator" &&
reflection.type.operator === "keyof"
) {
const type = context.checker.getTypeAtLocation(node);
reflection.type = new td.UnionType(type.types.map((type) => new td.LiteralType(type.value)));
}
} |
Love it! |
Could this be made to work for a generic parameter also? I've attempted adding the plugin, but I have a method like
And my documentation is
Thanks! |
Unfortunately, doing this everywhere is much more difficult. Types can be present in quite a few places, and a plugin would have to manually check each location to replace the type. For a type parameter's constraint, I believe this would do the trick (untested) // typedoc --plugin path/to/this/file.js
const td = require("typedoc");
/** @param {td.Application} app */
exports.load = function (app) {
app.converter.on(td.Converter.CREATE_TYPE_PARAMETER, resolveKeyof);
};
/**
* @param {td.Context} context
* @param {td.TypeParameterReflection} typeParam
*/
function resolveKeyof(context, typeParam) {
// Note: getSymbolFromReflection is internal, and will likely break in a future update
const symbol = context.project.getSymbolFromReflection(typeParam);
const declaration = symbol?.declarations?.[0]
if (!declaration) return;
if (typeParam.type.type === "typeOperator" && typeParam.type.operator === "keyof") {
const type = context.checker.getTypeAtLocation(declaration);
reflection.type = new td.UnionType(type.types.map((type) => new td.LiteralType(type.value)));
}
} |
Thanks for the response, really appreciate it 👍 I suspected it might be a bit tricky! |
Follow-up, I was able to achieve this without a plugin, and using the |
Search terms
keyof
, referencesExpected Behavior
Typedoc compiles this code just fine:
I would expect it to be able to also, at least, compile this – reading through the reference to
ThingConfig
as it does.Actual Behavior
Instead, I get this warning.
We have
--treatWarningsAsErrors
turned on, so this has become a problem :)Steps to reproduce the bug
Environment
The text was updated successfully, but these errors were encountered: