File: arrayAssignmentTest1.types

package info (click to toggle)
node-typescript 3.3.3333-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 324,548 kB
  • sloc: makefile: 6; sh: 3
file content (263 lines) | stat: -rw-r--r-- 5,178 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
=== tests/cases/compiler/arrayAssignmentTest1.ts ===
interface I1 {
	IM1():void[];
>IM1 : () => void[]
}

class C1 implements I1 { 
>C1 : C1

	IM1():void[] {return null;}
>IM1 : () => void[]
>null : null

	C1M1():C1[] {return null;}
>C1M1 : () => C1[]
>null : null
 }
class C2 extends C1 {
>C2 : C2
>C1 : C1

    C2M1():C2[] { return null;}
>C2M1 : () => C2[]
>null : null
}

class C3 {
>C3 : C3

    CM3M1() { return 3;}
>CM3M1 : () => number
>3 : 3
}


/*

This behaves unexpectedly with the following types:

Type 1 of any[]:

* Type 2 of the following throws an error but shouldn't: () => void[], SomeClass[], and {one: 1}[].

* Type 2 of the following doesn't throw an error but should: {one: 1}, new() => SomeClass, SomeClass.

*/
var a1 : any = null;
>a1 : any
>null : null

var c1 : C1 = new C1();
>c1 : C1
>new C1() : C1
>C1 : typeof C1

var i1 : I1 = c1;
>i1 : I1
>c1 : C1

var c2 : C2 = new C2();
>c2 : C2
>new C2() : C2
>C2 : typeof C2

var c3 : C3 = new C3();
>c3 : C3
>new C3() : C3
>C3 : typeof C3

var o1 = {one : 1};
>o1 : { one: number; }
>{one : 1} : { one: number; }
>one : number
>1 : 1

var f1 = function () { return new C1();}
>f1 : () => C1
>function () { return new C1();} : () => C1
>new C1() : C1
>C1 : typeof C1

var arr_any: any[] = [];
>arr_any : any[]
>[] : undefined[]

var arr_i1: I1[] = [];
>arr_i1 : I1[]
>[] : undefined[]

var arr_c1: C1[] = [];
>arr_c1 : C1[]
>[] : undefined[]

var arr_c2: C2[] = [];
>arr_c2 : C2[]
>[] : undefined[]

var arr_i1_2: I1[] = [];
>arr_i1_2 : I1[]
>[] : undefined[]

var arr_c1_2: C1[] = [];
>arr_c1_2 : C1[]
>[] : undefined[]

var arr_c2_2: C2[] = [];
>arr_c2_2 : C2[]
>[] : undefined[]

var arr_c3: C3[] = [];
>arr_c3 : C3[]
>[] : undefined[]

var i1_error: I1 = []; // should be an error - is
>i1_error : I1
>[] : undefined[]

var c1_error: C1 = []; // should be an error - is
>c1_error : C1
>[] : undefined[]

var c2_error: C2 = []; // should be an error - is
>c2_error : C2
>[] : undefined[]

var c3_error: C3 = []; // should be an error - is
>c3_error : C3
>[] : undefined[]


arr_any = arr_i1; // should be ok - is
>arr_any = arr_i1 : I1[]
>arr_any : any[]
>arr_i1 : I1[]

arr_any = arr_c1; // should be ok - is
>arr_any = arr_c1 : C1[]
>arr_any : any[]
>arr_c1 : C1[]

arr_any = arr_c2; // should be ok - is
>arr_any = arr_c2 : C2[]
>arr_any : any[]
>arr_c2 : C2[]

arr_any = arr_c3; // should be ok - is
>arr_any = arr_c3 : C3[]
>arr_any : any[]
>arr_c3 : C3[]

arr_i1 = arr_i1; // should be ok - subtype relationship - is
>arr_i1 = arr_i1 : I1[]
>arr_i1 : I1[]
>arr_i1 : I1[]

arr_i1 = arr_c1; // should be ok - subtype relationship - is
>arr_i1 = arr_c1 : C1[]
>arr_i1 : I1[]
>arr_c1 : C1[]

arr_i1 = arr_c2; // should be ok - subtype relationship - is
>arr_i1 = arr_c2 : C2[]
>arr_i1 : I1[]
>arr_c2 : C2[]

arr_i1 = arr_c3; // should be an error - is
>arr_i1 = arr_c3 : C3[]
>arr_i1 : I1[]
>arr_c3 : C3[]

arr_c1 = arr_c1; // should be ok - subtype relationship - is
>arr_c1 = arr_c1 : C1[]
>arr_c1 : C1[]
>arr_c1 : C1[]

arr_c1 = arr_c2; // should be ok - subtype relationship - is
>arr_c1 = arr_c2 : C2[]
>arr_c1 : C1[]
>arr_c2 : C2[]

arr_c1 = arr_i1; // should be an error - is
>arr_c1 = arr_i1 : I1[]
>arr_c1 : C1[]
>arr_i1 : I1[]

arr_c1 = arr_c3; // should be an error - is
>arr_c1 = arr_c3 : C3[]
>arr_c1 : C1[]
>arr_c3 : C3[]

arr_c2 = arr_c2; // should be ok - subtype relationship - is
>arr_c2 = arr_c2 : C2[]
>arr_c2 : C2[]
>arr_c2 : C2[]

arr_c2 = arr_c1; // should be an error - subtype relationship - is
>arr_c2 = arr_c1 : C1[]
>arr_c2 : C2[]
>arr_c1 : C1[]

arr_c2 = arr_i1; // should be an error - subtype relationship - is
>arr_c2 = arr_i1 : I1[]
>arr_c2 : C2[]
>arr_i1 : I1[]

arr_c2 = arr_c3; // should be an error - is
>arr_c2 = arr_c3 : C3[]
>arr_c2 : C2[]
>arr_c3 : C3[]

// "clean up bug" occurs at this point
// if you move these three expressions to another file, they raise an error
// something to do with state from the above propagating forward?
arr_c3 = arr_c2_2; // should be an error - is
>arr_c3 = arr_c2_2 : C2[]
>arr_c3 : C3[]
>arr_c2_2 : C2[]

arr_c3 = arr_c1_2; // should be an error - is
>arr_c3 = arr_c1_2 : C1[]
>arr_c3 : C3[]
>arr_c1_2 : C1[]

arr_c3 = arr_i1_2; // should be an error - is
>arr_c3 = arr_i1_2 : I1[]
>arr_c3 : C3[]
>arr_i1_2 : I1[]

arr_any = f1; // should be an error - is
>arr_any = f1 : () => C1
>arr_any : any[]
>f1 : () => C1

arr_any = o1; // should be an error - is
>arr_any = o1 : { one: number; }
>arr_any : any[]
>o1 : { one: number; }

arr_any = a1; // should be ok - is
>arr_any = a1 : any
>arr_any : any[]
>a1 : any

arr_any = c1; // should be an error - is
>arr_any = c1 : C1
>arr_any : any[]
>c1 : C1

arr_any = c2; // should be an error - is
>arr_any = c2 : C2
>arr_any : any[]
>c2 : C2

arr_any = c3; // should be an error - is
>arr_any = c3 : C3
>arr_any : any[]
>c3 : C3

arr_any = i1; // should be an error - is
>arr_any = i1 : I1
>arr_any : any[]
>i1 : I1