Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions type-generation/src/astToIR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
SourceFile,
SyntaxKind,
ts,
TypeElementMemberedNode,
TypeElementTypes,
TypeLiteralNode,
TypeNode,
Expand Down Expand Up @@ -365,9 +366,15 @@ class SyntheticTypeConverter {
}

doConversion(
nodes: Pick<TypeLiteralNode, "getMembers">[],
nodes: (TypeElementMemberedNode & Node)[],
modifiers: Modifier,
): ReferenceTypeIR {
const res = nodes.filter(
(x): x is TypeElementMemberedNode & TypeParameteredNode & Node =>
Node.isTypeParametered(x),
);
const typeParams = this.converter.getTypeParamsFromDecls(res);

let name = this.nameContext.join("__");
if (!name.endsWith("_iface")) {
name += "_iface";
Expand All @@ -384,7 +391,14 @@ class SyntheticTypeConverter {
(x) => !Node.isPropertyNamed(x) || pickSet.has(x.getName()),
);
}
const result = this.converter.interfaceToIR(name, [], members, [], [], []);
const result = this.converter.interfaceToIR(
name,
[],
members,
[],
[],
typeParams,
);
if (partial) {
for (const prop of result.properties) {
prop.isOptional = true;
Expand Down Expand Up @@ -501,10 +515,6 @@ class SyntheticTypeConverter {
}
if (res.kind === "interfaces") {
const { name, ifaces } = res;
const typeParams = this.converter.getTypeParamsFromDecls(ifaces);
if (typeParams.length > 0) {
throw new Error("Not handled");
}
this.nameContext.push(name);
const result = this.doConversion(ifaces, modifiers);
this.nameContext.pop();
Expand Down
18 changes: 18 additions & 0 deletions type-generation/tests/a.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1787,6 +1787,24 @@ describe("emit", () => {
`).trim(),
);
});
it("PartialTypeArg", () => {
const res = emitFile(`
interface A<T> { a: T; }
type D = Partial<A<string>>;
declare function f(): D;
`);
assert.strictEqual(
removeTypeIgnores(res.slice(1).join("\n\n")),
dedent(`
type D = D__Partial__A_iface

def f() -> D: ...

class D__Partial__A_iface[T](Protocol):
a: T | None = ...
`).trim(),
);
});
});
it("Composed type operators", () => {
const res = emitFile(`
Expand Down