Skip to content

Commit

Permalink
fix: correctly extract types from index signature declaration (#291)
Browse files Browse the repository at this point in the history
  • Loading branch information
tvillaren authored Nov 25, 2024
1 parent d9076dd commit 74abe78
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
12 changes: 12 additions & 0 deletions src/utils/traverseTypes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,18 @@ describe("traverseTypes", () => {
{ name: "Skill", partOfQualifiedName: false },
]);
});

it("should extract type in index signature", () => {
const source = `export interface Hero {
powers: {[name: string] : Power}
}`;

const result = extractNames(source);
expect(result).toEqual([
{ name: "Hero", partOfQualifiedName: false },
{ name: "Power", partOfQualifiedName: false },
]);
});
});
});

Expand Down
14 changes: 7 additions & 7 deletions src/utils/traverseTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ export function getReferencedTypeNames(
referenceTypeNames.add({ name: node.name.text, partOfQualifiedName: false });

const visitorExtract = (child: ts.Node) => {
if (!ts.isPropertySignature(child)) {
return;
}

const childNode = child as ts.PropertySignature;
if (childNode.type) {
handleTypeNode(childNode.type);
if (ts.isPropertySignature(child)) {
const childNode = child as ts.PropertySignature;
if (childNode.type) {
handleTypeNode(childNode.type);
}
} else if (ts.isIndexSignatureDeclaration(child) && child.type) {
handleTypeNode(child.type);
}
};

Expand Down

0 comments on commit 74abe78

Please sign in to comment.