docgen: add support for intersection types

This commit is contained in:
Patrik Oldsberg
2020-07-15 11:47:30 +02:00
parent ab450c3ad7
commit e692991226
3 changed files with 12 additions and 8 deletions
@@ -61,12 +61,16 @@ export default class ApiDocGenerator {
const id = this.getObjectPropertyLiteral(info, 'id');
const description = this.getObjectPropertyLiteral(info, 'description');
const interfaceInfo = this.getInterfaceInfo(typeArgs[0]);
if (!interfaceInfo) {
throw new Error('api has no info type argument');
}
return { id, name, source, description, interfaceInfo };
const rootTypeNode = typeArgs[0];
const typeNodes = ts.isIntersectionTypeNode(rootTypeNode)
? rootTypeNode.types.slice()
: [rootTypeNode];
const interfaceInfos = typeNodes.map(typeNode =>
this.getInterfaceInfo(typeNode),
);
return { id, name, source, description, interfaceInfos };
}
private getNodeDocs(node: ts.Node): string[] {
+2 -2
View File
@@ -47,9 +47,9 @@ export default class ApiDocPrinter {
// Remove line numbers from codeblocks
printer.style('.linenodiv{ display: none }');
printer.header(1, `shared/apis/${apiDoc.id}`);
printer.header(1, apiDoc.id);
const ifInfo = apiDoc.interfaceInfo;
const ifInfo = apiDoc.interfaceInfos[0];
if (ifInfo.docs.length) {
for (const doc of ifInfo.docs) {
+1 -1
View File
@@ -77,7 +77,7 @@ export type ApiDoc = {
name: string;
source: ts.SourceFile;
description: string;
interfaceInfo: InterfaceInfo;
interfaceInfos: InterfaceInfo[];
};
/**