Skip to content

Commit 3fc80fb

Browse files
authored
Make subclasses of jsobject as jsobject (#78)
This is maybe not the right way to do things but it fixes CI.
1 parent 93d87b4 commit 3fc80fb

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

type-generation/src/extract.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ function fixupClassBases(nameToCls: Map<string, InterfaceIR>): void {
6565
cls.concrete = true;
6666
break;
6767
}
68+
// If the base is a jsobject set the subclass to be a jsobject. This
69+
// probably shouldn't be necessary and indicates an issue somewhere
70+
// else.
71+
if (s?.jsobject) {
72+
cls.jsobject = true;
73+
}
6874
}
6975
}
7076
if (!cls.jsobject && !cls.concrete) {

type-generation/tests/a.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2004,6 +2004,39 @@ describe("emit", () => {
20042004
);
20052005
});
20062006
});
2007+
it("inheriting from jsobject is also jsobject", () => {
2008+
const res = emitFile(`
2009+
interface C {
2010+
a: string;
2011+
}
2012+
declare var C: {
2013+
prototype: C;
2014+
new(): C;
2015+
};
2016+
declare function f(a: C & {b: string}): void;
2017+
`);
2018+
// Maybe f__Sig0__a should inherit from C_iface instead? This doesn't happen
2019+
// in many places though so for now I am just trying to make it not broken.
2020+
assert.strictEqual(
2021+
removeTypeIgnores(res.slice(1).join("\n\n")),
2022+
dedent(`
2023+
def f(a: f__Sig0__a, /) -> None: ...
2024+
2025+
class C(C_iface, _JsObject):
2026+
@classmethod
2027+
def new(self, /) -> C: ...
2028+
2029+
class C_iface(Protocol):
2030+
a: str = ...
2031+
2032+
class f__Sig0__a__Intersection1(Protocol):
2033+
b: str = ...
2034+
2035+
class f__Sig0__a(f__Sig0__a__Intersection1, C, _JsObject):
2036+
pass
2037+
`).trim(),
2038+
);
2039+
});
20072040
describe("adjustments", () => {
20082041
it("setTimeout", () => {
20092042
const res = emitIRNoTypeIgnores(convertBuiltinFunction("setTimeout"));

0 commit comments

Comments
 (0)