Skip to content

Commit abd2a85

Browse files
committed
Adding tests
1 parent 47c9190 commit abd2a85

22 files changed

Lines changed: 1415 additions & 0 deletions
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
//// [fluentClasses.ts]
2+
class A {
3+
foo() {
4+
return this;
5+
}
6+
}
7+
class B extends A {
8+
bar() {
9+
return this;
10+
}
11+
}
12+
class C extends B {
13+
baz() {
14+
return this;
15+
}
16+
}
17+
var c: C;
18+
var z = c.foo().bar().baz(); // Fluent pattern
19+
20+
21+
//// [fluentClasses.js]
22+
var __extends = (this && this.__extends) || function (d, b) {
23+
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
24+
function __() { this.constructor = d; }
25+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
26+
};
27+
var A = (function () {
28+
function A() {
29+
}
30+
A.prototype.foo = function () {
31+
return this;
32+
};
33+
return A;
34+
})();
35+
var B = (function (_super) {
36+
__extends(B, _super);
37+
function B() {
38+
_super.apply(this, arguments);
39+
}
40+
B.prototype.bar = function () {
41+
return this;
42+
};
43+
return B;
44+
})(A);
45+
var C = (function (_super) {
46+
__extends(C, _super);
47+
function C() {
48+
_super.apply(this, arguments);
49+
}
50+
C.prototype.baz = function () {
51+
return this;
52+
};
53+
return C;
54+
})(B);
55+
var c;
56+
var z = c.foo().bar().baz(); // Fluent pattern
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
=== tests/cases/conformance/types/thisType/fluentClasses.ts ===
2+
class A {
3+
>A : Symbol(A, Decl(fluentClasses.ts, 0, 0))
4+
5+
foo() {
6+
>foo : Symbol(foo, Decl(fluentClasses.ts, 0, 9))
7+
8+
return this;
9+
>this : Symbol(A, Decl(fluentClasses.ts, 0, 0))
10+
}
11+
}
12+
class B extends A {
13+
>B : Symbol(B, Decl(fluentClasses.ts, 4, 1))
14+
>A : Symbol(A, Decl(fluentClasses.ts, 0, 0))
15+
16+
bar() {
17+
>bar : Symbol(bar, Decl(fluentClasses.ts, 5, 19))
18+
19+
return this;
20+
>this : Symbol(B, Decl(fluentClasses.ts, 4, 1))
21+
}
22+
}
23+
class C extends B {
24+
>C : Symbol(C, Decl(fluentClasses.ts, 9, 1))
25+
>B : Symbol(B, Decl(fluentClasses.ts, 4, 1))
26+
27+
baz() {
28+
>baz : Symbol(baz, Decl(fluentClasses.ts, 10, 19))
29+
30+
return this;
31+
>this : Symbol(C, Decl(fluentClasses.ts, 9, 1))
32+
}
33+
}
34+
var c: C;
35+
>c : Symbol(c, Decl(fluentClasses.ts, 15, 3))
36+
>C : Symbol(C, Decl(fluentClasses.ts, 9, 1))
37+
38+
var z = c.foo().bar().baz(); // Fluent pattern
39+
>z : Symbol(z, Decl(fluentClasses.ts, 16, 3))
40+
>c.foo().bar().baz : Symbol(C.baz, Decl(fluentClasses.ts, 10, 19))
41+
>c.foo().bar : Symbol(B.bar, Decl(fluentClasses.ts, 5, 19))
42+
>c.foo : Symbol(A.foo, Decl(fluentClasses.ts, 0, 9))
43+
>c : Symbol(c, Decl(fluentClasses.ts, 15, 3))
44+
>foo : Symbol(A.foo, Decl(fluentClasses.ts, 0, 9))
45+
>bar : Symbol(B.bar, Decl(fluentClasses.ts, 5, 19))
46+
>baz : Symbol(C.baz, Decl(fluentClasses.ts, 10, 19))
47+
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
=== tests/cases/conformance/types/thisType/fluentClasses.ts ===
2+
class A {
3+
>A : A
4+
5+
foo() {
6+
>foo : () => this
7+
8+
return this;
9+
>this : this
10+
}
11+
}
12+
class B extends A {
13+
>B : B
14+
>A : A
15+
16+
bar() {
17+
>bar : () => this
18+
19+
return this;
20+
>this : this
21+
}
22+
}
23+
class C extends B {
24+
>C : C
25+
>B : B
26+
27+
baz() {
28+
>baz : () => this
29+
30+
return this;
31+
>this : this
32+
}
33+
}
34+
var c: C;
35+
>c : C
36+
>C : C
37+
38+
var z = c.foo().bar().baz(); // Fluent pattern
39+
>z : C
40+
>c.foo().bar().baz() : C
41+
>c.foo().bar().baz : () => C
42+
>c.foo().bar() : C
43+
>c.foo().bar : () => C
44+
>c.foo() : C
45+
>c.foo : () => C
46+
>c : C
47+
>foo : () => C
48+
>bar : () => C
49+
>baz : () => C
50+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//// [fluentInterfaces.ts]
2+
interface A {
3+
foo(): this;
4+
}
5+
interface B extends A {
6+
bar(): this;
7+
}
8+
interface C extends B {
9+
baz(): this;
10+
}
11+
var c: C;
12+
var z = c.foo().bar().baz(); // Fluent pattern
13+
14+
15+
//// [fluentInterfaces.js]
16+
var c;
17+
var z = c.foo().bar().baz(); // Fluent pattern
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
=== tests/cases/conformance/types/thisType/fluentInterfaces.ts ===
2+
interface A {
3+
>A : Symbol(A, Decl(fluentInterfaces.ts, 0, 0))
4+
5+
foo(): this;
6+
>foo : Symbol(foo, Decl(fluentInterfaces.ts, 0, 13))
7+
}
8+
interface B extends A {
9+
>B : Symbol(B, Decl(fluentInterfaces.ts, 2, 1))
10+
>A : Symbol(A, Decl(fluentInterfaces.ts, 0, 0))
11+
12+
bar(): this;
13+
>bar : Symbol(bar, Decl(fluentInterfaces.ts, 3, 23))
14+
}
15+
interface C extends B {
16+
>C : Symbol(C, Decl(fluentInterfaces.ts, 5, 1))
17+
>B : Symbol(B, Decl(fluentInterfaces.ts, 2, 1))
18+
19+
baz(): this;
20+
>baz : Symbol(baz, Decl(fluentInterfaces.ts, 6, 23))
21+
}
22+
var c: C;
23+
>c : Symbol(c, Decl(fluentInterfaces.ts, 9, 3))
24+
>C : Symbol(C, Decl(fluentInterfaces.ts, 5, 1))
25+
26+
var z = c.foo().bar().baz(); // Fluent pattern
27+
>z : Symbol(z, Decl(fluentInterfaces.ts, 10, 3))
28+
>c.foo().bar().baz : Symbol(C.baz, Decl(fluentInterfaces.ts, 6, 23))
29+
>c.foo().bar : Symbol(B.bar, Decl(fluentInterfaces.ts, 3, 23))
30+
>c.foo : Symbol(A.foo, Decl(fluentInterfaces.ts, 0, 13))
31+
>c : Symbol(c, Decl(fluentInterfaces.ts, 9, 3))
32+
>foo : Symbol(A.foo, Decl(fluentInterfaces.ts, 0, 13))
33+
>bar : Symbol(B.bar, Decl(fluentInterfaces.ts, 3, 23))
34+
>baz : Symbol(C.baz, Decl(fluentInterfaces.ts, 6, 23))
35+
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
=== tests/cases/conformance/types/thisType/fluentInterfaces.ts ===
2+
interface A {
3+
>A : A
4+
5+
foo(): this;
6+
>foo : () => this
7+
}
8+
interface B extends A {
9+
>B : B
10+
>A : A
11+
12+
bar(): this;
13+
>bar : () => this
14+
}
15+
interface C extends B {
16+
>C : C
17+
>B : B
18+
19+
baz(): this;
20+
>baz : () => this
21+
}
22+
var c: C;
23+
>c : C
24+
>C : C
25+
26+
var z = c.foo().bar().baz(); // Fluent pattern
27+
>z : C
28+
>c.foo().bar().baz() : C
29+
>c.foo().bar().baz : () => C
30+
>c.foo().bar() : C
31+
>c.foo().bar : () => C
32+
>c.foo() : C
33+
>c.foo : () => C
34+
>c : C
35+
>foo : () => C
36+
>bar : () => C
37+
>baz : () => C
38+
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
tests/cases/conformance/types/thisType/thisTypeErrors.ts(1,9): error TS2526: 'this' type is available only in a non-static member of a class or interface.
2+
tests/cases/conformance/types/thisType/thisTypeErrors.ts(2,14): error TS2526: 'this' type is available only in a non-static member of a class or interface.
3+
tests/cases/conformance/types/thisType/thisTypeErrors.ts(3,9): error TS2526: 'this' type is available only in a non-static member of a class or interface.
4+
tests/cases/conformance/types/thisType/thisTypeErrors.ts(5,16): error TS2526: 'this' type is available only in a non-static member of a class or interface.
5+
tests/cases/conformance/types/thisType/thisTypeErrors.ts(5,23): error TS2526: 'this' type is available only in a non-static member of a class or interface.
6+
tests/cases/conformance/types/thisType/thisTypeErrors.ts(6,12): error TS2526: 'this' type is available only in a non-static member of a class or interface.
7+
tests/cases/conformance/types/thisType/thisTypeErrors.ts(11,13): error TS2526: 'this' type is available only in a non-static member of a class or interface.
8+
tests/cases/conformance/types/thisType/thisTypeErrors.ts(12,14): error TS2526: 'this' type is available only in a non-static member of a class or interface.
9+
tests/cases/conformance/types/thisType/thisTypeErrors.ts(13,18): error TS2526: 'this' type is available only in a non-static member of a class or interface.
10+
tests/cases/conformance/types/thisType/thisTypeErrors.ts(14,23): error TS2526: 'this' type is available only in a non-static member of a class or interface.
11+
tests/cases/conformance/types/thisType/thisTypeErrors.ts(15,15): error TS2526: 'this' type is available only in a non-static member of a class or interface.
12+
tests/cases/conformance/types/thisType/thisTypeErrors.ts(15,22): error TS2526: 'this' type is available only in a non-static member of a class or interface.
13+
tests/cases/conformance/types/thisType/thisTypeErrors.ts(19,13): error TS2526: 'this' type is available only in a non-static member of a class or interface.
14+
tests/cases/conformance/types/thisType/thisTypeErrors.ts(20,14): error TS2526: 'this' type is available only in a non-static member of a class or interface.
15+
tests/cases/conformance/types/thisType/thisTypeErrors.ts(21,18): error TS2526: 'this' type is available only in a non-static member of a class or interface.
16+
tests/cases/conformance/types/thisType/thisTypeErrors.ts(22,23): error TS2526: 'this' type is available only in a non-static member of a class or interface.
17+
tests/cases/conformance/types/thisType/thisTypeErrors.ts(23,15): error TS2526: 'this' type is available only in a non-static member of a class or interface.
18+
tests/cases/conformance/types/thisType/thisTypeErrors.ts(23,22): error TS2526: 'this' type is available only in a non-static member of a class or interface.
19+
tests/cases/conformance/types/thisType/thisTypeErrors.ts(27,15): error TS2526: 'this' type is available only in a non-static member of a class or interface.
20+
tests/cases/conformance/types/thisType/thisTypeErrors.ts(28,17): error TS2526: 'this' type is available only in a non-static member of a class or interface.
21+
tests/cases/conformance/types/thisType/thisTypeErrors.ts(29,19): error TS2526: 'this' type is available only in a non-static member of a class or interface.
22+
tests/cases/conformance/types/thisType/thisTypeErrors.ts(29,26): error TS2526: 'this' type is available only in a non-static member of a class or interface.
23+
tests/cases/conformance/types/thisType/thisTypeErrors.ts(35,19): error TS2526: 'this' type is available only in a non-static member of a class or interface.
24+
tests/cases/conformance/types/thisType/thisTypeErrors.ts(36,20): error TS2331: 'this' cannot be referenced in a module or namespace body.
25+
tests/cases/conformance/types/thisType/thisTypeErrors.ts(41,14): error TS2526: 'this' type is available only in a non-static member of a class or interface.
26+
tests/cases/conformance/types/thisType/thisTypeErrors.ts(41,21): error TS2526: 'this' type is available only in a non-static member of a class or interface.
27+
tests/cases/conformance/types/thisType/thisTypeErrors.ts(46,23): error TS2526: 'this' type is available only in a non-static member of a class or interface.
28+
tests/cases/conformance/types/thisType/thisTypeErrors.ts(46,30): error TS2526: 'this' type is available only in a non-static member of a class or interface.
29+
tests/cases/conformance/types/thisType/thisTypeErrors.ts(50,18): error TS2526: 'this' type is available only in a non-static member of a class or interface.
30+
tests/cases/conformance/types/thisType/thisTypeErrors.ts(50,25): error TS2526: 'this' type is available only in a non-static member of a class or interface.
31+
32+
33+
==== tests/cases/conformance/types/thisType/thisTypeErrors.ts (30 errors) ====
34+
var x1: this;
35+
~~~~
36+
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
37+
var x2: { a: this };
38+
~~~~
39+
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
40+
var x3: this[];
41+
~~~~
42+
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
43+
44+
function f1(x: this): this {
45+
~~~~
46+
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
47+
~~~~
48+
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
49+
var y: this;
50+
~~~~
51+
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
52+
return this;
53+
}
54+
55+
interface I1 {
56+
a: { x: this };
57+
~~~~
58+
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
59+
b: { (): this };
60+
~~~~
61+
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
62+
c: { new (): this };
63+
~~~~
64+
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
65+
d: { [x: string]: this };
66+
~~~~
67+
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
68+
e: { f(x: this): this };
69+
~~~~
70+
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
71+
~~~~
72+
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
73+
}
74+
75+
class C1 {
76+
a: { x: this };
77+
~~~~
78+
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
79+
b: { (): this };
80+
~~~~
81+
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
82+
c: { new (): this };
83+
~~~~
84+
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
85+
d: { [x: string]: this };
86+
~~~~
87+
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
88+
e: { f(x: this): this };
89+
~~~~
90+
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
91+
~~~~
92+
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
93+
}
94+
95+
class C2 {
96+
static x: this;
97+
~~~~
98+
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
99+
static y = <this>undefined;
100+
~~~~
101+
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
102+
static foo(x: this): this {
103+
~~~~
104+
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
105+
~~~~
106+
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
107+
return undefined;
108+
}
109+
}
110+
111+
namespace N1 {
112+
export var x: this;
113+
~~~~
114+
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
115+
export var y = this;
116+
~~~~
117+
!!! error TS2331: 'this' cannot be referenced in a module or namespace body.
118+
}
119+
120+
class C3 {
121+
x1 = {
122+
g(x: this): this {
123+
~~~~
124+
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
125+
~~~~
126+
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
127+
return undefined;
128+
}
129+
}
130+
f() {
131+
function g(x: this): this {
132+
~~~~
133+
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
134+
~~~~
135+
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
136+
return undefined;
137+
}
138+
let x2 = {
139+
h(x: this): this {
140+
~~~~
141+
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
142+
~~~~
143+
!!! error TS2526: 'this' type is available only in a non-static member of a class or interface.
144+
return undefined;
145+
}
146+
}
147+
}
148+
}
149+

0 commit comments

Comments
 (0)