File: typeArgumentInferenceConstructSignatures.js

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 (206 lines) | stat: -rw-r--r-- 8,040 bytes parent folder | download | duplicates (7)
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
//// [typeArgumentInferenceConstructSignatures.ts]
// Generic call with no parameters
interface NoParams {
    new <T>();
}
var noParams: NoParams;
new noParams();
new noParams<string>();
new noParams<{}>();

// Generic call with parameters but none use type parameter type
interface noGenericParams {
    new <T>(n: string);
}
var noGenericParams: noGenericParams;
new noGenericParams('');
new noGenericParams<number>('');
new noGenericParams<{}>('');

// Generic call with multiple type parameters and only one used in parameter type annotation
interface someGenerics1 {
    new <T, U>(n: T, m: number);
}
var someGenerics1: someGenerics1;
new someGenerics1(3, 4);
new someGenerics1<string, number>(3, 4); // Error
new someGenerics1<number, {}>(3, 4);

// Generic call with argument of function type whose parameter is of type parameter type
interface someGenerics2a {
    new <T>(n: (x: T) => void);
}
var someGenerics2a: someGenerics2a;
new someGenerics2a((n: string) => n);
new someGenerics2a<string>((n: string) => n);
new someGenerics2a<string>((n) => n.substr(0));

interface someGenerics2b {
    new <T, U>(n: (x: T, y: U) => void);
}
var someGenerics2b: someGenerics2b;
new someGenerics2b((n: string, x: number) => n);
new someGenerics2b<string, number>((n: string, t: number) => n);
new someGenerics2b<string, number>((n, t) => n.substr(t * t));

// Generic call with argument of function type whose parameter is not of type parameter type but body/return type uses type parameter
interface someGenerics3 {
    new <T>(producer: () => T);
}
var someGenerics3: someGenerics3;
new someGenerics3(() => '');
new someGenerics3<Window>(() => undefined);
new someGenerics3<number>(() => 3);

// 2 parameter generic call with argument 1 of type parameter type and argument 2 of function type whose parameter is of type parameter type
interface someGenerics4 {
    new <T, U>(n: T, f: (x: U) => void);
}
var someGenerics4: someGenerics4;
new someGenerics4(4, () => null);
new someGenerics4<string, number>('', () => 3);
new someGenerics4<string, number>('', (x: string) => ''); // Error
new someGenerics4<string, number>(null, null);

// 2 parameter generic call with argument 2 of type parameter type and argument 1 of function type whose parameter is of type parameter type
interface someGenerics5 {
    new <U, T>(n: T, f: (x: U) => void);
}
var someGenerics5: someGenerics5;
new someGenerics5(4, () => null);
new someGenerics5<number, string>('', () => 3);
new someGenerics5<number, string>('', (x: string) => ''); // Error
new someGenerics5<string, number>(null, null);

// Generic call with multiple arguments of function types that each have parameters of the same generic type
interface someGenerics6 {
    new <A>(a: (a: A) => A, b: (b: A) => A, c: (c: A) => A);
}
var someGenerics6: someGenerics6;
new someGenerics6(n => n, n => n, n => n);
new someGenerics6<number>(n => n, n => n, n => n);
new someGenerics6<number>((n: number) => n, (n: string) => n, (n: number) => n); // Error
new someGenerics6<number>((n: number) => n, (n: number) => n, (n: number) => n);

// Generic call with multiple arguments of function types that each have parameters of different generic type
interface someGenerics7 {
    new <A, B, C>(a: (a: A) => A, b: (b: B) => B, c: (c: C) => C);
}
var someGenerics7: someGenerics7;
new someGenerics7(n => n, n => n, n => n);
new someGenerics7<number, string, number>(n => n, n => n, n => n);
new someGenerics7<number, string, number>((n: number) => n, (n: string) => n, (n: number) => n);

// Generic call with argument of generic function type
interface someGenerics8 {
    new <T>(n: T): T;
}
var someGenerics8: someGenerics8;
var x = new someGenerics8(someGenerics7);
new x<string, string, string>(null, null, null);

// Generic call with multiple parameters of generic type passed arguments with no best common type
interface someGenerics9 {
    new <T>(a: T, b: T, c: T): T;
}
var someGenerics9: someGenerics9;
var a9a = new someGenerics9('', 0, []);
var a9a: {};
var a9b = new someGenerics9<{ a?: number; b?: string; }>({ a: 0 }, { b: '' }, null);
var a9b: { a?: number; b?: string; };

// Generic call with multiple parameters of generic type passed arguments with multiple best common types
interface A91 {
    x: number;
    y?: string;
}
interface A92 {
    x: number;
    z?: Window;
}
var a9e = new someGenerics9(undefined, { x: 6, z: window }, { x: 6, y: '' });
var a9e: {};
var a9f = new someGenerics9<A92>(undefined, { x: 6, z: window }, { x: 6, y: '' });
var a9f: A92;

// Generic call with multiple parameters of generic type passed arguments with a single best common type
var a9d = new someGenerics9({ x: 3 }, { x: 6 }, { x: 6 });
var a9d: { x: number; };

// Generic call with multiple parameters of generic type where one argument is of type 'any'
var anyVar: any;
var a = new someGenerics9(7, anyVar, 4);
var a: any;

// Generic call with multiple parameters of generic type where one argument is [] and the other is not 'any'
var arr = new someGenerics9([], null, undefined);
var arr: any[];



//// [typeArgumentInferenceConstructSignatures.js]
var noParams;
new noParams();
new noParams();
new noParams();
var noGenericParams;
new noGenericParams('');
new noGenericParams('');
new noGenericParams('');
var someGenerics1;
new someGenerics1(3, 4);
new someGenerics1(3, 4); // Error
new someGenerics1(3, 4);
var someGenerics2a;
new someGenerics2a(function (n) { return n; });
new someGenerics2a(function (n) { return n; });
new someGenerics2a(function (n) { return n.substr(0); });
var someGenerics2b;
new someGenerics2b(function (n, x) { return n; });
new someGenerics2b(function (n, t) { return n; });
new someGenerics2b(function (n, t) { return n.substr(t * t); });
var someGenerics3;
new someGenerics3(function () { return ''; });
new someGenerics3(function () { return undefined; });
new someGenerics3(function () { return 3; });
var someGenerics4;
new someGenerics4(4, function () { return null; });
new someGenerics4('', function () { return 3; });
new someGenerics4('', function (x) { return ''; }); // Error
new someGenerics4(null, null);
var someGenerics5;
new someGenerics5(4, function () { return null; });
new someGenerics5('', function () { return 3; });
new someGenerics5('', function (x) { return ''; }); // Error
new someGenerics5(null, null);
var someGenerics6;
new someGenerics6(function (n) { return n; }, function (n) { return n; }, function (n) { return n; });
new someGenerics6(function (n) { return n; }, function (n) { return n; }, function (n) { return n; });
new someGenerics6(function (n) { return n; }, function (n) { return n; }, function (n) { return n; }); // Error
new someGenerics6(function (n) { return n; }, function (n) { return n; }, function (n) { return n; });
var someGenerics7;
new someGenerics7(function (n) { return n; }, function (n) { return n; }, function (n) { return n; });
new someGenerics7(function (n) { return n; }, function (n) { return n; }, function (n) { return n; });
new someGenerics7(function (n) { return n; }, function (n) { return n; }, function (n) { return n; });
var someGenerics8;
var x = new someGenerics8(someGenerics7);
new x(null, null, null);
var someGenerics9;
var a9a = new someGenerics9('', 0, []);
var a9a;
var a9b = new someGenerics9({ a: 0 }, { b: '' }, null);
var a9b;
var a9e = new someGenerics9(undefined, { x: 6, z: window }, { x: 6, y: '' });
var a9e;
var a9f = new someGenerics9(undefined, { x: 6, z: window }, { x: 6, y: '' });
var a9f;
// Generic call with multiple parameters of generic type passed arguments with a single best common type
var a9d = new someGenerics9({ x: 3 }, { x: 6 }, { x: 6 });
var a9d;
// Generic call with multiple parameters of generic type where one argument is of type 'any'
var anyVar;
var a = new someGenerics9(7, anyVar, 4);
var a;
// Generic call with multiple parameters of generic type where one argument is [] and the other is not 'any'
var arr = new someGenerics9([], null, undefined);
var arr;