Skip to content

Commit a3de3ba

Browse files
committed
Add a test for generic mixins.
1 parent 732c6fd commit a3de3ba

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

test/flavors/custom-element/member-test.ts

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ tsTest("Member types can be retrieved", t => {
3535
t.truthy(isAssignableToType({ kind: "NUMBER" }, toSimpleType(type, checker)));
3636
});
3737

38-
tsTest("Property declaration member types are specialized", t => {
38+
tsTest("Property declaration member types are specialized (classes)", t => {
3939
const {
4040
results: [result],
4141
checker
@@ -70,6 +70,44 @@ tsTest("Property declaration member types are specialized", t => {
7070
t.truthy(isAssignableToType(optional({ kind: "BOOLEAN" }), toSimpleType(booleanElementPropType, checker)));
7171
});
7272

73+
tsTest("Property declaration member types are specialized (mixins)", t => {
74+
const {
75+
results: [result],
76+
checker
77+
} = analyzeTextWithCurrentTsModule([
78+
{
79+
fileName: "main.ts",
80+
text: `
81+
const SomeMixin = <T, C>(Base: C) => {
82+
class Mixin extends Base {
83+
prop?: T;
84+
}
85+
return Mixin;
86+
}
87+
88+
class NumberPropElement extends SomeMixin<number>(HTMLElement) {}
89+
90+
class BooleanPropElement extends SomeMixin<boolean>(HTMLElement) {}
91+
92+
declare global {
93+
interface HTMLElementTagNameMap {
94+
"number-prop-element": NumberPropElement;
95+
"boolean-prop-element": BooleanPropElement;
96+
}
97+
}
98+
`
99+
}
100+
]);
101+
102+
const numberElementDecl = result.componentDefinitions.find(x => x.tagName === "number-prop-element")!.declaration!;
103+
const numberElementPropType = getComponentProp(numberElementDecl.members, "prop")!.type!(numberElementDecl);
104+
t.truthy(isAssignableToType(optional({ kind: "NUMBER" }), toSimpleType(numberElementPropType, checker)));
105+
106+
const booleanElementDecl = result.componentDefinitions.find(x => x.tagName === "boolean-prop-element")!.declaration!;
107+
const booleanElementPropType = getComponentProp(booleanElementDecl.members, "prop")!.type!(booleanElementDecl);
108+
t.truthy(isAssignableToType(optional({ kind: "BOOLEAN" }), toSimpleType(booleanElementPropType, checker)));
109+
});
110+
73111
tsTest("Getter member types are specialized", t => {
74112
const {
75113
results: [result],

0 commit comments

Comments
 (0)