File: variadicTuples2.errors.txt

package info (click to toggle)
node-typescript 5.0.4%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 459,140 kB
  • sloc: javascript: 1,972,754; makefile: 6; sh: 1
file content (297 lines) | stat: -rw-r--r-- 19,373 bytes parent folder | download
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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
tests/cases/conformance/types/tuple/variadicTuples2.ts(7,34): error TS1265: A rest element cannot follow another rest element.
tests/cases/conformance/types/tuple/variadicTuples2.ts(8,34): error TS1266: An optional element cannot follow a rest element.
tests/cases/conformance/types/tuple/variadicTuples2.ts(9,30): error TS1257: A required element cannot follow an optional element.
tests/cases/conformance/types/tuple/variadicTuples2.ts(42,1): error TS2322: Type '[string, string, number, number]' is not assignable to type '[...string[], number]'.
  Type at positions 0 through 2 in source is not compatible with type at position 0 in target.
    Type 'number' is not assignable to type 'string'.
tests/cases/conformance/types/tuple/variadicTuples2.ts(48,5): error TS2345: Argument of type '["abc", "def", 5, 6]' is not assignable to parameter of type '[...strs: string[], num: number]'.
  Type at positions 0 through 2 in source is not compatible with type at position 0 in target.
    Type 'number' is not assignable to type 'string'.
tests/cases/conformance/types/tuple/variadicTuples2.ts(51,1): error TS2322: Type '[number]' is not assignable to type '[number, ...string[], number]'.
  Source has 1 element(s) but target requires 2.
tests/cases/conformance/types/tuple/variadicTuples2.ts(53,1): error TS2322: Type '[number, number, number]' is not assignable to type '[number, ...string[], number]'.
  Type at position 1 in source is not compatible with type at position 1 in target.
    Type 'number' is not assignable to type 'string'.
tests/cases/conformance/types/tuple/variadicTuples2.ts(56,1): error TS2322: Type '[number, string, number, string]' is not assignable to type '[number, ...string[], number]'.
  Type at positions 1 through 2 in source is not compatible with type at position 1 in target.
    Type 'number' is not assignable to type 'string'.
tests/cases/conformance/types/tuple/variadicTuples2.ts(57,8): error TS2322: Type 'boolean' is not assignable to type 'number'.
tests/cases/conformance/types/tuple/variadicTuples2.ts(58,1): error TS2322: Type '[number, string, string, boolean]' is not assignable to type '[number, ...string[], number]'.
  Type at position 3 in source is not compatible with type at position 2 in target.
    Type 'boolean' is not assignable to type 'number'.
tests/cases/conformance/types/tuple/variadicTuples2.ts(61,1): error TS2345: Argument of type '[]' is not assignable to parameter of type '[...strs: string[], n2: number]'.
  Source has 0 element(s) but target requires 1.
tests/cases/conformance/types/tuple/variadicTuples2.ts(63,8): error TS2345: Argument of type '[1, 2]' is not assignable to parameter of type '[...strs: string[], n2: number]'.
  Type at position 0 in source is not compatible with type at position 0 in target.
    Type 'number' is not assignable to type 'string'.
tests/cases/conformance/types/tuple/variadicTuples2.ts(66,8): error TS2345: Argument of type '["abc", 1, "def"]' is not assignable to parameter of type '[...strs: string[], n2: number]'.
  Type at positions 0 through 1 in source is not compatible with type at position 0 in target.
    Type 'number' is not assignable to type 'string'.
tests/cases/conformance/types/tuple/variadicTuples2.ts(67,5): error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'number'.
tests/cases/conformance/types/tuple/variadicTuples2.ts(68,8): error TS2345: Argument of type '["abc", "def", true]' is not assignable to parameter of type '[...strs: string[], n2: number]'.
  Type at position 2 in source is not compatible with type at position 1 in target.
    Type 'boolean' is not assignable to type 'number'.
tests/cases/conformance/types/tuple/variadicTuples2.ts(71,5): error TS2322: Type '[number, number]' is not assignable to type '[number, ...T]'.
  Source provides no match for variadic element at position 1 in target.
tests/cases/conformance/types/tuple/variadicTuples2.ts(72,5): error TS2322: Type '[number, ...number[]]' is not assignable to type '[number, ...T]'.
  Target requires 2 element(s) but source may have fewer.
tests/cases/conformance/types/tuple/variadicTuples2.ts(73,5): error TS2322: Type '[number, ...T]' is not assignable to type '[number, number]'.
  Variadic element at position 1 in source does not match element at position 1 in target.
tests/cases/conformance/types/tuple/variadicTuples2.ts(74,5): error TS2322: Type '[number, ...T]' is not assignable to type '[number, ...number[]]'.
  Type at position 1 in source is not compatible with type at position 1 in target.
    Type 'T' is not assignable to type 'number[]'.
      Type 'unknown[]' is not assignable to type 'number[]'.
        Type 'unknown' is not assignable to type 'number'.
tests/cases/conformance/types/tuple/variadicTuples2.ts(79,5): error TS2322: Type '[number, string, ...any[]]' is not assignable to type '[number, ...number[]]'.
  Type at positions 1 through 2 in source is not compatible with type at position 1 in target.
    Type 'string' is not assignable to type 'number'.
tests/cases/conformance/types/tuple/variadicTuples2.ts(111,16): error TS2345: Argument of type '[1, 2, 3, 4]' is not assignable to parameter of type '[...number[], (...values: number[]) => void]'.
  Type at position 3 in source is not compatible with type at position 1 in target.
    Type 'number' is not assignable to type '(...values: number[]) => void'.
tests/cases/conformance/types/tuple/variadicTuples2.ts(112,6): error TS2345: Argument of type 'string[]' is not assignable to parameter of type '[...string[], (...values: string[]) => void]'.
  Source provides no match for required element at position 1 in target.
tests/cases/conformance/types/tuple/variadicTuples2.ts(115,5): error TS2345: Argument of type '[]' is not assignable to parameter of type '[...unknown[], unknown, unknown]'.
  Source has 0 element(s) but target requires 2.
tests/cases/conformance/types/tuple/variadicTuples2.ts(116,5): error TS2345: Argument of type '[number]' is not assignable to parameter of type '[...unknown[], unknown, unknown]'.
  Source has 1 element(s) but target requires 2.
tests/cases/conformance/types/tuple/variadicTuples2.ts(121,5): error TS2345: Argument of type '[]' is not assignable to parameter of type '[unknown, ...unknown[], unknown]'.
  Source has 0 element(s) but target requires 2.
tests/cases/conformance/types/tuple/variadicTuples2.ts(122,5): error TS2345: Argument of type '[number]' is not assignable to parameter of type '[unknown, ...unknown[], unknown]'.
  Source has 1 element(s) but target requires 2.
tests/cases/conformance/types/tuple/variadicTuples2.ts(132,16): error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'.
tests/cases/conformance/types/tuple/variadicTuples2.ts(133,16): error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'.
tests/cases/conformance/types/tuple/variadicTuples2.ts(134,25): error TS2345: Argument of type '["blah2", 1, 2, 3]' is not assignable to parameter of type '[...string[], number]'.
  Type at positions 0 through 2 in source is not compatible with type at position 0 in target.
    Type 'number' is not assignable to type 'string'.


==== tests/cases/conformance/types/tuple/variadicTuples2.ts (29 errors) ====
    // Declarations
    
    type V00 = [number, ...string[]];
    type V01 = [...string[], number];
    type V03 = [number, ...string[], number];
    
    type V10 = [number, ...string[], ...boolean[]];  // Error
                                     ~~~~~~~~~~~~
!!! error TS1265: A rest element cannot follow another rest element.
    type V11 = [number, ...string[], boolean?];  // Error
                                     ~~~~~~~~
!!! error TS1266: An optional element cannot follow a rest element.
    type V12 = [number, string?, boolean];  // Error
                                 ~~~~~~~
!!! error TS1257: A required element cannot follow an optional element.
    
    // Normalization
    
    type Tup3<T extends unknown[], U extends unknown[], V extends unknown[]> = [...T, ...U, ...V];
    
    type V20 = Tup3<[number], string[], [number]>;  // [number, ...string[], number]
    type V21 = Tup3<[number], [string?], [boolean]>;  // [number, string | undefined, boolean]
    type V22 = Tup3<[number], string[], boolean[]>;  // [number, (string | boolean)[]]
    type V23 = Tup3<[number], string[], [boolean?]>;  // [number, (string | boolean | undefined)[]]
    type V24 = Tup3<[number], [boolean?], string[]>;  // [number, boolean?, ...string[]]
    type V25 = Tup3<string[], number[], boolean[]>;  // (string | number | boolean)[]
    type V26 = Tup3<string[], number[], [boolean]>;  // [...(string | number)[], boolean]
    type V27 = Tup3<[number?], [string], [boolean?]>;  // [number | undefined, string, boolean?]
    
    type V30<A extends unknown[]> = Tup3<A, string[], number[]>;  // [...A, ...(string | number)[]]
    type V31<A extends unknown[]> = Tup3<string[], A, number[]>;  // (string | number | A[number])[]
    type V32<A extends unknown[]> = Tup3<string[], number[], A>;  // [...(string | number)[], ...A]
    
    type V40<A extends unknown[]> = Tup3<A, [string?], number[]>;  // [...A, string?, ...number[]]
    type V41<A extends unknown[]> = Tup3<[string?], A, number[]>;  // [string?, ...A, ...number[]]
    type V42<A extends unknown[]> = Tup3<[string?], number[], A>;  // [string?, ...number[], ...A]
    
    type V50<A extends unknown[]> = Tup3<A, string[], [number?]>;  // [...A, ...(string | number | undefined)[]]
    type V51<A extends unknown[]> = Tup3<string[], A, [number?]>;  // (string | number | A[number] | undefined)[]
    type V52<A extends unknown[]> = Tup3<string[], [number?], A>;  // [...(string | number | undefined)[], ...A]
    
    // Assignability
    
    declare let tt1: [...string[], number];
    tt1 = [5];
    tt1 = ['abc', 5];
    tt1 = ['abc', 'def', 5];
    tt1 = ['abc', 'def', 5, 6];  // Error
    ~~~
!!! error TS2322: Type '[string, string, number, number]' is not assignable to type '[...string[], number]'.
!!! error TS2322:   Type at positions 0 through 2 in source is not compatible with type at position 0 in target.
!!! error TS2322:     Type 'number' is not assignable to type 'string'.
    
    declare function ft1(...args: [...strs: string[], num: number]): void;
    ft1(5);
    ft1('abc', 5);
    ft1('abc', 'def', 5);
    ft1('abc', 'def', 5, 6);  // Error
        ~~~~~~~~~~~~~~~~~~
!!! error TS2345: Argument of type '["abc", "def", 5, 6]' is not assignable to parameter of type '[...strs: string[], num: number]'.
!!! error TS2345:   Type at positions 0 through 2 in source is not compatible with type at position 0 in target.
!!! error TS2345:     Type 'number' is not assignable to type 'string'.
    
    declare let tt2: [number, ...string[], number];
    tt2 = [0];  // Error
    ~~~
!!! error TS2322: Type '[number]' is not assignable to type '[number, ...string[], number]'.
!!! error TS2322:   Source has 1 element(s) but target requires 2.
    tt2 = [0, 1];
    tt2 = [0, 1, 2];  // Error
    ~~~
!!! error TS2322: Type '[number, number, number]' is not assignable to type '[number, ...string[], number]'.
!!! error TS2322:   Type at position 1 in source is not compatible with type at position 1 in target.
!!! error TS2322:     Type 'number' is not assignable to type 'string'.
    tt2 = [0, 'abc', 1];
    tt2 = [0, 'abc', 'def', 1];
    tt2 = [0, 'abc', 1, 'def'];  // Error
    ~~~
!!! error TS2322: Type '[number, string, number, string]' is not assignable to type '[number, ...string[], number]'.
!!! error TS2322:   Type at positions 1 through 2 in source is not compatible with type at position 1 in target.
!!! error TS2322:     Type 'number' is not assignable to type 'string'.
    tt2 = [true, 'abc', 'def', 1];  // Error
           ~~~~
!!! error TS2322: Type 'boolean' is not assignable to type 'number'.
    tt2 = [0, 'abc', 'def', true];  // Error
    ~~~
!!! error TS2322: Type '[number, string, string, boolean]' is not assignable to type '[number, ...string[], number]'.
!!! error TS2322:   Type at position 3 in source is not compatible with type at position 2 in target.
!!! error TS2322:     Type 'boolean' is not assignable to type 'number'.
    
    declare function ft2(n1: number, ...rest: [...strs: string[], n2: number]): void;
    ft2(0);  // Error
    ~~~~~~
!!! error TS2345: Argument of type '[]' is not assignable to parameter of type '[...strs: string[], n2: number]'.
!!! error TS2345:   Source has 0 element(s) but target requires 1.
    ft2(0, 1);
    ft2(0, 1, 2);  // Error
           ~~~~
!!! error TS2345: Argument of type '[1, 2]' is not assignable to parameter of type '[...strs: string[], n2: number]'.
!!! error TS2345:   Type at position 0 in source is not compatible with type at position 0 in target.
!!! error TS2345:     Type 'number' is not assignable to type 'string'.
    ft2(0, 'abc', 1);
    ft2(0, 'abc', 'def', 1);
    ft2(0, 'abc', 1, 'def');  // Error
           ~~~~~~~~~~~~~~~
!!! error TS2345: Argument of type '["abc", 1, "def"]' is not assignable to parameter of type '[...strs: string[], n2: number]'.
!!! error TS2345:   Type at positions 0 through 1 in source is not compatible with type at position 0 in target.
!!! error TS2345:     Type 'number' is not assignable to type 'string'.
    ft2(true, 'abc', 'def', 1);  // Error
        ~~~~
!!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'number'.
    ft2(0, 'abc', 'def', true);  // Error
           ~~~~~~~~~~~~~~~~~~
!!! error TS2345: Argument of type '["abc", "def", true]' is not assignable to parameter of type '[...strs: string[], n2: number]'.
!!! error TS2345:   Type at position 2 in source is not compatible with type at position 1 in target.
!!! error TS2345:     Type 'boolean' is not assignable to type 'number'.
    
    function ft3<T extends unknown[]>(x: [number, ...T], y: [number, number], z: [number, ...number[]]) {
        x = y;  // Error
        ~
!!! error TS2322: Type '[number, number]' is not assignable to type '[number, ...T]'.
!!! error TS2322:   Source provides no match for variadic element at position 1 in target.
        x = z;  // Error
        ~
!!! error TS2322: Type '[number, ...number[]]' is not assignable to type '[number, ...T]'.
!!! error TS2322:   Target requires 2 element(s) but source may have fewer.
        y = x;  // Error
        ~
!!! error TS2322: Type '[number, ...T]' is not assignable to type '[number, number]'.
!!! error TS2322:   Variadic element at position 1 in source does not match element at position 1 in target.
        z = x;  // Error
        ~
!!! error TS2322: Type '[number, ...T]' is not assignable to type '[number, ...number[]]'.
!!! error TS2322:   Type at position 1 in source is not compatible with type at position 1 in target.
!!! error TS2322:     Type 'T' is not assignable to type 'number[]'.
!!! error TS2322:       Type 'unknown[]' is not assignable to type 'number[]'.
!!! error TS2322:         Type 'unknown' is not assignable to type 'number'.
    }
    
    // repro #50216
    declare let tt3: [number, string, ...any[]]
    let tt4: [number, ...number[]] = tt3  // Error
        ~~~
!!! error TS2322: Type '[number, string, ...any[]]' is not assignable to type '[number, ...number[]]'.
!!! error TS2322:   Type at positions 1 through 2 in source is not compatible with type at position 1 in target.
!!! error TS2322:     Type 'string' is not assignable to type 'number'.
    
    // Inference
    
    function pipe<T extends readonly unknown[]>(...args: [...T, (...values: T) => void]) {
        const callback = args[args.length - 1] as (...values: T) => void;
        const values = args.slice(0, -1) as unknown as T;
        callback(...values);
    }
    
    pipe("foo", 123, true, (a, b, c) => {
        a;  // string
        b;  // number
        c;  // boolean
    })
    
    pipe("foo", 123, true, (...x) => {
        x;  // [string, number, boolean]
    });
    
    declare const sa: string[];
    
    pipe(...sa, (...x) => {
        x;  // string[]
    });
    
    pipe(1, ...sa, 2, (...x) => {
        x;  // [number, ...string[], number]
        let qq = x[x.length - 1];
        let ww = x[0]
    });
    
    pipe<number[]>(1, 2, 3, 4);  // Error
                   ~~~~~~~~~~
!!! error TS2345: Argument of type '[1, 2, 3, 4]' is not assignable to parameter of type '[...number[], (...values: number[]) => void]'.
!!! error TS2345:   Type at position 3 in source is not compatible with type at position 1 in target.
!!! error TS2345:     Type 'number' is not assignable to type '(...values: number[]) => void'.
    pipe(...sa);  // Error
         ~~~~~
!!! error TS2345: Argument of type 'string[]' is not assignable to parameter of type '[...string[], (...values: string[]) => void]'.
!!! error TS2345:   Source provides no match for required element at position 1 in target.
    
    declare function fn1<T, U>(t: [...unknown[], T, U]): [T, U];
    fn1([]);  // Error
        ~~
!!! error TS2345: Argument of type '[]' is not assignable to parameter of type '[...unknown[], unknown, unknown]'.
!!! error TS2345:   Source has 0 element(s) but target requires 2.
    fn1([1]);  // Error
        ~~~
!!! error TS2345: Argument of type '[number]' is not assignable to parameter of type '[...unknown[], unknown, unknown]'.
!!! error TS2345:   Source has 1 element(s) but target requires 2.
    fn1([1, 'abc']);  // [number, string]
    fn1([1, 'abc', true]);  // [string, boolean]
    
    declare function fn2<T, U>(t: [T, ...unknown[], U]): [T, U];
    fn2([]);  // Error
        ~~
!!! error TS2345: Argument of type '[]' is not assignable to parameter of type '[unknown, ...unknown[], unknown]'.
!!! error TS2345:   Source has 0 element(s) but target requires 2.
    fn2([1]);  // Error
        ~~~
!!! error TS2345: Argument of type '[number]' is not assignable to parameter of type '[unknown, ...unknown[], unknown]'.
!!! error TS2345:   Source has 1 element(s) but target requires 2.
    fn2([1, 'abc']);  // [number, string]
    fn2([1, 'abc', true]);  // [number, boolean]
    
    // Repro from #39595
    
    declare function foo<S extends readonly [string, ...string[]]>(...stringsAndNumber: readonly [...S, number]): [...S, number];
    
    const a1 = foo('blah1', 1);
    const b1 = foo('blah1', 'blah2', 1);
    const c1 = foo(1);  // Error
                   ~
!!! error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'.
    const d1 = foo(1, 2);  // Error
                   ~
!!! error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'.
    const e1 = foo('blah1', 'blah2', 1, 2, 3);  // Error
                            ~~~~~~~~~~~~~~~~
!!! error TS2345: Argument of type '["blah2", 1, 2, 3]' is not assignable to parameter of type '[...string[], number]'.
!!! error TS2345:   Type at positions 0 through 2 in source is not compatible with type at position 0 in target.
!!! error TS2345:     Type 'number' is not assignable to type 'string'.