-
Notifications
You must be signed in to change notification settings - Fork 0
/
typedoc-plugin-quickinfo.js
65 lines (55 loc) · 1.68 KB
/
typedoc-plugin-quickinfo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//@ts-check
// https://github.com/TypeStrong/typedoc/issues/1258
// Supports: typedoc@0.23
const {
Converter,
ReflectionKind,
TypeScript: ts,
UnknownType,
} = require('typedoc');
/** @param {import("typedoc").Application} param0 */
exports.load = function ({ application }) {
const printer = ts.createPrinter();
/** @type {Map<import("typedoc").DeclarationReflection, UnknownType>} */
const typeOverrides = new Map();
application.converter.on(
Converter.EVENT_CREATE_DECLARATION,
/**
*
* @param {import("typedoc/dist/lib/converter/context").Context} context
* @param {import("typedoc").DeclarationReflection} reflection
*/
(context, reflection) => {
const node =
context.project.getSymbolFromReflection(reflection)?.declarations?.[0];
if (reflection.kind === ReflectionKind.TypeAlias && node) {
if (reflection.comment?.getTag('@quickinfo')) {
reflection.comment.removeTags('@quickinfo');
const type = context.checker.getTypeAtLocation(node);
const typeNode = context.checker.typeToTypeNode(
type,
node.getSourceFile(),
ts.NodeBuilderFlags.InTypeAlias,
);
console.log(type)
typeOverrides.set(
reflection,
new UnknownType(
printer.printNode(
ts.EmitHint.Unspecified,
typeNode,
node.getSourceFile(),
),
),
);
}
}
},
);
application.converter.on(Converter.EVENT_RESOLVE_BEGIN, () => {
for (const [refl, type] of typeOverrides) {
refl.type = type;
}
typeOverrides.clear();
});
};