Skip to content

Commit 19319b2

Browse files
committed
Adding test for declaration files
1 parent 29f6036 commit 19319b2

4 files changed

Lines changed: 447 additions & 0 deletions

File tree

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
//// [declarationFiles.ts]
2+
3+
class C1 {
4+
x: this;
5+
f(x: this): this { return undefined; }
6+
constructor(x: this) { }
7+
}
8+
9+
class C2 {
10+
[x: string]: this;
11+
}
12+
13+
interface Foo<T> {
14+
x: T;
15+
y: this;
16+
}
17+
18+
class C3 {
19+
a: this[];
20+
b: [this, this];
21+
c: this | Date;
22+
d: this & Date;
23+
e: (((this)));
24+
f: (x: this) => this;
25+
g: new (x: this) => this;
26+
h: Foo<this>;
27+
i: Foo<this | (() => this)>;
28+
j: (x: any) => x is this;
29+
}
30+
31+
class C4 {
32+
x1 = { a: this };
33+
x2 = [this];
34+
x3 = [{ a: this }];
35+
x4 = () => this;
36+
f1() {
37+
return { a: this };
38+
}
39+
f2() {
40+
return [this];
41+
}
42+
f3() {
43+
return [{ a: this }];
44+
}
45+
f4() {
46+
return () => this;
47+
}
48+
}
49+
50+
51+
//// [declarationFiles.js]
52+
var C1 = (function () {
53+
function C1(x) {
54+
}
55+
C1.prototype.f = function (x) { return undefined; };
56+
return C1;
57+
})();
58+
var C2 = (function () {
59+
function C2() {
60+
}
61+
return C2;
62+
})();
63+
var C3 = (function () {
64+
function C3() {
65+
}
66+
return C3;
67+
})();
68+
var C4 = (function () {
69+
function C4() {
70+
var _this = this;
71+
this.x1 = { a: this };
72+
this.x2 = [this];
73+
this.x3 = [{ a: this }];
74+
this.x4 = function () { return _this; };
75+
}
76+
C4.prototype.f1 = function () {
77+
return { a: this };
78+
};
79+
C4.prototype.f2 = function () {
80+
return [this];
81+
};
82+
C4.prototype.f3 = function () {
83+
return [{ a: this }];
84+
};
85+
C4.prototype.f4 = function () {
86+
var _this = this;
87+
return function () { return _this; };
88+
};
89+
return C4;
90+
})();
91+
92+
93+
//// [declarationFiles.d.ts]
94+
declare class C1 {
95+
x: this;
96+
f(x: this): this;
97+
constructor(x: this);
98+
}
99+
declare class C2 {
100+
[x: string]: this;
101+
}
102+
interface Foo<T> {
103+
x: T;
104+
y: this;
105+
}
106+
declare class C3 {
107+
a: this[];
108+
b: [this, this];
109+
c: this | Date;
110+
d: this & Date;
111+
e: (((this)));
112+
f: (x: this) => this;
113+
g: new (x: this) => this;
114+
h: Foo<this>;
115+
i: Foo<this | (() => this)>;
116+
j: (x: any) => x is this;
117+
}
118+
declare class C4 {
119+
x1: {
120+
a: C4;
121+
};
122+
x2: this[];
123+
x3: {
124+
a: C4;
125+
}[];
126+
x4: () => this;
127+
f1(): {
128+
a: C4;
129+
};
130+
f2(): this[];
131+
f3(): {
132+
a: C4;
133+
}[];
134+
f4(): () => this;
135+
}
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
=== tests/cases/conformance/types/thisType/declarationFiles.ts ===
2+
3+
class C1 {
4+
>C1 : Symbol(C1, Decl(declarationFiles.ts, 0, 0))
5+
6+
x: this;
7+
>x : Symbol(x, Decl(declarationFiles.ts, 1, 10))
8+
9+
f(x: this): this { return undefined; }
10+
>f : Symbol(f, Decl(declarationFiles.ts, 2, 12))
11+
>x : Symbol(x, Decl(declarationFiles.ts, 3, 6))
12+
>undefined : Symbol(undefined)
13+
14+
constructor(x: this) { }
15+
>x : Symbol(x, Decl(declarationFiles.ts, 4, 16))
16+
}
17+
18+
class C2 {
19+
>C2 : Symbol(C2, Decl(declarationFiles.ts, 5, 1))
20+
21+
[x: string]: this;
22+
>x : Symbol(x, Decl(declarationFiles.ts, 8, 5))
23+
}
24+
25+
interface Foo<T> {
26+
>Foo : Symbol(Foo, Decl(declarationFiles.ts, 9, 1))
27+
>T : Symbol(T, Decl(declarationFiles.ts, 11, 14))
28+
29+
x: T;
30+
>x : Symbol(x, Decl(declarationFiles.ts, 11, 18))
31+
>T : Symbol(T, Decl(declarationFiles.ts, 11, 14))
32+
33+
y: this;
34+
>y : Symbol(y, Decl(declarationFiles.ts, 12, 9))
35+
}
36+
37+
class C3 {
38+
>C3 : Symbol(C3, Decl(declarationFiles.ts, 14, 1))
39+
40+
a: this[];
41+
>a : Symbol(a, Decl(declarationFiles.ts, 16, 10))
42+
43+
b: [this, this];
44+
>b : Symbol(b, Decl(declarationFiles.ts, 17, 14))
45+
46+
c: this | Date;
47+
>c : Symbol(c, Decl(declarationFiles.ts, 18, 20))
48+
>Date : Symbol(Date, Decl(lib.d.ts, 633, 23), Decl(lib.d.ts, 815, 11))
49+
50+
d: this & Date;
51+
>d : Symbol(d, Decl(declarationFiles.ts, 19, 19))
52+
>Date : Symbol(Date, Decl(lib.d.ts, 633, 23), Decl(lib.d.ts, 815, 11))
53+
54+
e: (((this)));
55+
>e : Symbol(e, Decl(declarationFiles.ts, 20, 19))
56+
57+
f: (x: this) => this;
58+
>f : Symbol(f, Decl(declarationFiles.ts, 21, 18))
59+
>x : Symbol(x, Decl(declarationFiles.ts, 22, 8))
60+
61+
g: new (x: this) => this;
62+
>g : Symbol(g, Decl(declarationFiles.ts, 22, 25))
63+
>x : Symbol(x, Decl(declarationFiles.ts, 23, 12))
64+
65+
h: Foo<this>;
66+
>h : Symbol(h, Decl(declarationFiles.ts, 23, 29))
67+
>Foo : Symbol(Foo, Decl(declarationFiles.ts, 9, 1))
68+
69+
i: Foo<this | (() => this)>;
70+
>i : Symbol(i, Decl(declarationFiles.ts, 24, 17))
71+
>Foo : Symbol(Foo, Decl(declarationFiles.ts, 9, 1))
72+
73+
j: (x: any) => x is this;
74+
>j : Symbol(j, Decl(declarationFiles.ts, 25, 32))
75+
>x : Symbol(x, Decl(declarationFiles.ts, 26, 8))
76+
>x : Symbol(x, Decl(declarationFiles.ts, 26, 8))
77+
}
78+
79+
class C4 {
80+
>C4 : Symbol(C4, Decl(declarationFiles.ts, 27, 1))
81+
82+
x1 = { a: this };
83+
>x1 : Symbol(x1, Decl(declarationFiles.ts, 29, 10))
84+
>a : Symbol(a, Decl(declarationFiles.ts, 30, 10))
85+
>this : Symbol(C4, Decl(declarationFiles.ts, 27, 1))
86+
87+
x2 = [this];
88+
>x2 : Symbol(x2, Decl(declarationFiles.ts, 30, 21))
89+
>this : Symbol(C4, Decl(declarationFiles.ts, 27, 1))
90+
91+
x3 = [{ a: this }];
92+
>x3 : Symbol(x3, Decl(declarationFiles.ts, 31, 16))
93+
>a : Symbol(a, Decl(declarationFiles.ts, 32, 11))
94+
>this : Symbol(C4, Decl(declarationFiles.ts, 27, 1))
95+
96+
x4 = () => this;
97+
>x4 : Symbol(x4, Decl(declarationFiles.ts, 32, 23))
98+
>this : Symbol(C4, Decl(declarationFiles.ts, 27, 1))
99+
100+
f1() {
101+
>f1 : Symbol(f1, Decl(declarationFiles.ts, 33, 20))
102+
103+
return { a: this };
104+
>a : Symbol(a, Decl(declarationFiles.ts, 35, 16))
105+
>this : Symbol(C4, Decl(declarationFiles.ts, 27, 1))
106+
}
107+
f2() {
108+
>f2 : Symbol(f2, Decl(declarationFiles.ts, 36, 5))
109+
110+
return [this];
111+
>this : Symbol(C4, Decl(declarationFiles.ts, 27, 1))
112+
}
113+
f3() {
114+
>f3 : Symbol(f3, Decl(declarationFiles.ts, 39, 5))
115+
116+
return [{ a: this }];
117+
>a : Symbol(a, Decl(declarationFiles.ts, 41, 17))
118+
>this : Symbol(C4, Decl(declarationFiles.ts, 27, 1))
119+
}
120+
f4() {
121+
>f4 : Symbol(f4, Decl(declarationFiles.ts, 42, 5))
122+
123+
return () => this;
124+
>this : Symbol(C4, Decl(declarationFiles.ts, 27, 1))
125+
}
126+
}
127+

0 commit comments

Comments
 (0)