Skip to content

Commit 56b1dcd

Browse files
committed
Add tests
1 parent 763df85 commit 56b1dcd

File tree

3 files changed

+222
-0
lines changed

3 files changed

+222
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// @declaration: true
2+
3+
type Constructor<T> = new(...args: any[]) => T;
4+
5+
class Base {
6+
constructor(public x: number, public y: number) {}
7+
}
8+
9+
class Derived extends Base {
10+
constructor(x: number, y: number, public z: number) {
11+
super(x, y);
12+
}
13+
}
14+
15+
interface Printable {
16+
print(): void;
17+
}
18+
19+
const Printable = <T extends Constructor<Base>>(superClass: T): Constructor<Printable> & { message: string } & T =>
20+
class extends superClass {
21+
static message = "hello";
22+
print() {
23+
const output = this.x + "," + this.y;
24+
}
25+
}
26+
27+
interface Tagged {
28+
_tag: string;
29+
}
30+
31+
function Tagged<T extends Constructor<{}>>(superClass: T): Constructor<Tagged> & T {
32+
class C extends superClass {
33+
_tag: string;
34+
constructor(...args: any[]) {
35+
super(...args);
36+
this._tag = "hello";
37+
}
38+
}
39+
return C;
40+
}
41+
42+
const Thing1 = Tagged(Derived);
43+
const Thing2 = Tagged(Printable(Derived));
44+
Thing2.message;
45+
46+
function f1() {
47+
const thing = new Thing1(1, 2, 3);
48+
thing.x;
49+
thing._tag;
50+
}
51+
52+
function f2() {
53+
const thing = new Thing2(1, 2, 3);
54+
thing.x;
55+
thing._tag;
56+
thing.print();
57+
}
58+
59+
class Thing3 extends Thing2 {
60+
constructor(tag: string) {
61+
super(10, 20, 30);
62+
this._tag = tag;
63+
}
64+
test() {
65+
this.print();
66+
}
67+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
type Constructor<T> = new(...args: any[]) => T;
2+
3+
class Base {
4+
constructor(public x: number, public y: number) {}
5+
}
6+
7+
class Derived extends Base {
8+
constructor(x: number, y: number, public z: number) {
9+
super(x, y);
10+
}
11+
}
12+
13+
const Printable = <T extends Constructor<Base>>(superClass: T) => class extends superClass {
14+
static message = "hello";
15+
print() {
16+
const output = this.x + "," + this.y;
17+
}
18+
}
19+
20+
function Tagged<T extends Constructor<{}>>(superClass: T) {
21+
class C extends superClass {
22+
_tag: string;
23+
constructor(...args: any[]) {
24+
super(...args);
25+
this._tag = "hello";
26+
}
27+
}
28+
return C;
29+
}
30+
31+
const Thing1 = Tagged(Derived);
32+
const Thing2 = Tagged(Printable(Derived));
33+
Thing2.message;
34+
35+
function f1() {
36+
const thing = new Thing1(1, 2, 3);
37+
thing.x;
38+
thing._tag;
39+
}
40+
41+
function f2() {
42+
const thing = new Thing2(1, 2, 3);
43+
thing.x;
44+
thing._tag;
45+
thing.print();
46+
}
47+
48+
class Thing3 extends Thing2 {
49+
constructor(tag: string) {
50+
super(10, 20, 30);
51+
this._tag = tag;
52+
}
53+
test() {
54+
this.print();
55+
}
56+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
// @declaration: true
2+
3+
declare class C1 {
4+
public a: number;
5+
protected b: number;
6+
private c: number;
7+
constructor(s: string);
8+
constructor(n: number);
9+
}
10+
11+
declare class M1 {
12+
constructor(...args: any[]);
13+
p: number;
14+
static p: number;
15+
}
16+
17+
declare class M2 {
18+
constructor(...args: any[]);
19+
f(): number;
20+
static f(): number;
21+
}
22+
23+
declare const Mixed1: typeof M1 & typeof C1;
24+
declare const Mixed2: typeof C1 & typeof M1;
25+
declare const Mixed3: typeof M2 & typeof M1 & typeof C1;
26+
declare const Mixed4: typeof C1 & typeof M1 & typeof M2;
27+
declare const Mixed5: typeof M1 & typeof M2;
28+
29+
function f1() {
30+
let x1 = new Mixed1("hello");
31+
let x2 = new Mixed1(42);
32+
let x3 = new Mixed2("hello");
33+
let x4 = new Mixed2(42);
34+
let x5 = new Mixed3("hello");
35+
let x6 = new Mixed3(42);
36+
let x7 = new Mixed4("hello");
37+
let x8 = new Mixed4(42);
38+
let x9 = new Mixed5();
39+
}
40+
41+
function f2() {
42+
let x = new Mixed1("hello");
43+
x.a;
44+
x.p;
45+
Mixed1.p;
46+
}
47+
48+
function f3() {
49+
let x = new Mixed2("hello");
50+
x.a;
51+
x.p;
52+
Mixed2.p;
53+
}
54+
55+
function f4() {
56+
let x = new Mixed3("hello");
57+
x.a;
58+
x.p;
59+
x.f();
60+
Mixed3.p;
61+
Mixed3.f();
62+
}
63+
64+
function f5() {
65+
let x = new Mixed4("hello");
66+
x.a;
67+
x.p;
68+
x.f();
69+
Mixed4.p;
70+
Mixed4.f();
71+
}
72+
73+
function f6() {
74+
let x = new Mixed5();
75+
x.p;
76+
x.f();
77+
Mixed5.p;
78+
Mixed5.f();
79+
}
80+
81+
class C2 extends Mixed1 {
82+
constructor() {
83+
super("hello");
84+
this.a;
85+
this.b;
86+
this.p;
87+
}
88+
}
89+
90+
class C3 extends Mixed3 {
91+
constructor() {
92+
super(42);
93+
this.a;
94+
this.b;
95+
this.p;
96+
this.f();
97+
}
98+
f() { return super.f(); }
99+
}

0 commit comments

Comments
 (0)