Skip to content

Commit

Permalink
[extensions] added index signatures to signature-plugin (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
lunaroyster authored Nov 3, 2023
1 parent c1e9513 commit 65e1363
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions modules/extensions/util/signature-plugin/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,21 @@ exports.load = function (app) {
},
priority: 0,
toObject: (x, obj) => {
obj.stringifiedInterface = `interface ${x.name} {\n${x.children
.map((c) => ` ${c.name}: ${c.type.toString()},`)
.join("\n")}\n}`;
const childrenParts = (x.children ?? []).map(
(c) => ` ${c.name}: ${c.type.toString()},`
);
const indexSigParts = x.indexSignature?.parameters?.length
? x.indexSignature.parameters.map(
(p) =>
` [${p.name}: ${p.type.toString()}]: ${
x.indexSignature.type.name
}`
)
: "";

const partsString = [...childrenParts, ...indexSigParts].join("\n");
obj.stringifiedInterface = `interface ${x.name} {\n${partsString}\n}`;

return obj;
},
});
Expand Down

0 comments on commit 65e1363

Please sign in to comment.