Skip to content

Commit b40a7c8

Browse files
authored
feat: support types that extends objects from other files (#24)
1 parent 7300f45 commit b40a7c8

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/parse.ts

+20-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,22 @@ export function parse(opts: DocsParseOptions) {
4545
});
4646

4747
return (api: string) => {
48-
const apiInterface = interfaces.find(i => i.name === api) || null;
48+
let apiInterface = interfaces.find(i => i.name === api) || null;
49+
50+
/**
51+
* Add methods of import(many is used in `extends`)
52+
*/
53+
const allImportObject = interfaces
54+
.filter(i => apiInterface?.importObject.includes(i.name) && i.name !== api)
55+
.map(i => i.importObject);
56+
57+
const otherMethod = interfaces
58+
.filter(i => [...new Set(allImportObject.flat())].includes(i.name))
59+
.map(d => d.methods)|| null;
60+
61+
if (apiInterface !== null && otherMethod && otherMethod.length > 0) {
62+
apiInterface.methods = [...new Set(apiInterface?.methods.concat(otherMethod.flat(1)))];
63+
}
4964

5065
const data: DocsData = {
5166
api: apiInterface,
@@ -173,13 +188,17 @@ function getInterface(
173188
const symbol = typeChecker.getSymbolAtLocation(node.name);
174189
const docs = symbol ? serializeSymbol(typeChecker, symbol) : null;
175190

191+
// @ts-ignore
192+
const importObject = node.parent?.locals?.keys() || []
193+
176194
const i: DocsInterface = {
177195
name: interfaceName,
178196
slug: slugify(interfaceName),
179197
docs: docs?.docs || '',
180198
tags: docs?.tags || [],
181199
methods,
182200
properties,
201+
importObject: [...importObject].filter((d: string) => d !== interfaceName)
183202
};
184203

185204
return i;

src/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export interface DocsInterface {
2020
tags: DocsTagInfo[];
2121
methods: DocsInterfaceMethod[];
2222
properties: DocsInterfaceProperty[];
23+
importObject: string[];
2324
}
2425

2526
export interface DocsEnum {

0 commit comments

Comments
 (0)