Skip to content

Commit 74abe78

Browse files
authored
fix: correctly extract types from index signature declaration (#291)
1 parent d9076dd commit 74abe78

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

src/utils/traverseTypes.test.ts

+12
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,18 @@ describe("traverseTypes", () => {
477477
{ name: "Skill", partOfQualifiedName: false },
478478
]);
479479
});
480+
481+
it("should extract type in index signature", () => {
482+
const source = `export interface Hero {
483+
powers: {[name: string] : Power}
484+
}`;
485+
486+
const result = extractNames(source);
487+
expect(result).toEqual([
488+
{ name: "Hero", partOfQualifiedName: false },
489+
{ name: "Power", partOfQualifiedName: false },
490+
]);
491+
});
480492
});
481493
});
482494

src/utils/traverseTypes.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ export function getReferencedTypeNames(
3838
referenceTypeNames.add({ name: node.name.text, partOfQualifiedName: false });
3939

4040
const visitorExtract = (child: ts.Node) => {
41-
if (!ts.isPropertySignature(child)) {
42-
return;
43-
}
44-
45-
const childNode = child as ts.PropertySignature;
46-
if (childNode.type) {
47-
handleTypeNode(childNode.type);
41+
if (ts.isPropertySignature(child)) {
42+
const childNode = child as ts.PropertySignature;
43+
if (childNode.type) {
44+
handleTypeNode(childNode.type);
45+
}
46+
} else if (ts.isIndexSignatureDeclaration(child) && child.type) {
47+
handleTypeNode(child.type);
4848
}
4949
};
5050

0 commit comments

Comments
 (0)