Skip to content

Commit 7a406a8

Browse files
Add conversion for named tuple (#66)
* Add conversion for named tuple * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent e0b0655 commit 7a406a8

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

type-generation/src/astToIR.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,12 @@ export class Converter {
717717
return arrayType(eltType);
718718
}
719719
if (Node.isTupleTypeNode(typeNode)) {
720-
const elts = typeNode.getElements().map((elt) => this.typeToIR(elt));
720+
const elts = typeNode.getElements().map((elt) => {
721+
if (Node.isNamedTupleMember(elt)) {
722+
return this.typeToIR(elt.getTypeNode());
723+
}
724+
return this.typeToIR(elt);
725+
});
721726
return tupleType(elts);
722727
}
723728
if (Node.isTypePredicate(typeNode)) {

type-generation/tests/a.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1783,6 +1783,20 @@ describe("emit", () => {
17831783
);
17841784
});
17851785
});
1786+
it("named tuple", () => {
1787+
const res = emitFile(`
1788+
declare var x: [
1789+
key: string,
1790+
value: string
1791+
];
1792+
`);
1793+
assert.strictEqual(
1794+
removeTypeIgnores(res.slice(1).join("\n\n")),
1795+
dedent(`
1796+
x: tuple[str, str] = ...
1797+
`).trim(),
1798+
);
1799+
});
17861800
describe("adjustments", () => {
17871801
it("setTimeout", () => {
17881802
const res = emitIRNoTypeIgnores(convertBuiltinFunction("setTimeout"));

0 commit comments

Comments
 (0)