@@ -39,12 +39,11 @@ tests/cases/conformance/types/tuple/variadicTuples1.ts(191,5): error TS2322: Typ
39
39
'U' could be instantiated with an arbitrary type which could be unrelated to 'readonly string[]'.
40
40
tests/cases/conformance/types/tuple/variadicTuples1.ts(203,5): error TS2322: Type 'string' is not assignable to type 'keyof [1, 2, ...T]'.
41
41
Type '"2"' is not assignable to type 'number | "0" | "length" | "toString" | "toLocaleString" | "pop" | "push" | "concat" | "join" | "reverse" | "shift" | "slice" | "sort" | "splice" | "unshift" | "indexOf" | "lastIndexOf" | "every" | "some" | "forEach" | "map" | "filter" | "reduce" | "reduceRight" | "1"'.
42
- tests/cases/conformance/types/tuple/variadicTuples1.ts(333,14): error TS7019: Rest parameter 'x' implicitly has an 'any[]' type.
43
- tests/cases/conformance/types/tuple/variadicTuples1.ts(341,19): error TS2322: Type 'string' is not assignable to type 'number | undefined'.
44
- tests/cases/conformance/types/tuple/variadicTuples1.ts(342,19): error TS2322: Type 'string' is not assignable to type 'number | undefined'.
42
+ tests/cases/conformance/types/tuple/variadicTuples1.ts(346,14): error TS7019: Rest parameter 'x' implicitly has an 'any[]' type.
43
+ tests/cases/conformance/types/tuple/variadicTuples1.ts(354,26): error TS2322: Type 'string' is not assignable to type 'number | undefined'.
45
44
46
45
47
- ==== tests/cases/conformance/types/tuple/variadicTuples1.ts (21 errors) ====
46
+ ==== tests/cases/conformance/types/tuple/variadicTuples1.ts (20 errors) ====
48
47
// Variadics in tuple types
49
48
50
49
type TV0<T extends unknown[]> = [string, ...T];
@@ -313,50 +312,54 @@ tests/cases/conformance/types/tuple/variadicTuples1.ts(342,19): error TS2322: Ty
313
312
// Inference between variadic tuple types
314
313
315
314
type First<T extends readonly unknown[]> = T[0];
316
- type DropFirst<T extends readonly unknown[]> = T extends readonly [any, ...infer U] ? U : [...T];
315
+ type DropFirst<T extends readonly unknown[]> = T extends readonly [any? , ...infer U] ? U : [...T];
317
316
318
- type Last<T extends readonly unknown[]> = T extends readonly [...infer _, infer U] ? U : undefined;
319
- type DropLast<T extends readonly unknown[]> = T extends readonly [...infer U, any] ? U : [...T];
317
+ type Last<T extends readonly unknown[]> = T extends readonly [...infer _, infer U] ? U : T extends readonly [...infer _, (infer U)?] ? U | undefined : undefined;
318
+ type DropLast<T extends readonly unknown[]> = T extends readonly [...infer U, any? ] ? U : [...T];
320
319
321
320
type T00 = First<[number, symbol, string]>;
322
321
type T01 = First<[symbol, string]>;
323
322
type T02 = First<[string]>;
324
323
type T03 = First<[number, symbol, ...string[]]>;
325
324
type T04 = First<[symbol, ...string[]]>;
326
- type T05 = First<string[]>;
327
- type T06 = First<[]>;
328
- type T07 = First<any>;
329
- type T08 = First<never>;
325
+ type T05 = First<[string?]>;
326
+ type T06 = First<string[]>;
327
+ type T07 = First<[]>;
328
+ type T08 = First<any>;
329
+ type T09 = First<never>;
330
330
331
331
type T10 = DropFirst<[number, symbol, string]>;
332
332
type T11 = DropFirst<[symbol, string]>;
333
333
type T12 = DropFirst<[string]>;
334
334
type T13 = DropFirst<[number, symbol, ...string[]]>;
335
335
type T14 = DropFirst<[symbol, ...string[]]>;
336
- type T15 = DropFirst<string[]>;
337
- type T16 = DropFirst<[]>;
338
- type T17 = DropFirst<any>;
339
- type T18 = DropFirst<never>;
336
+ type T15 = DropFirst<[string?]>;
337
+ type T16 = DropFirst<string[]>;
338
+ type T17 = DropFirst<[]>;
339
+ type T18 = DropFirst<any>;
340
+ type T19 = DropFirst<never>;
340
341
341
342
type T20 = Last<[number, symbol, string]>;
342
343
type T21 = Last<[symbol, string]>;
343
344
type T22 = Last<[string]>;
344
345
type T23 = Last<[number, symbol, ...string[]]>;
345
346
type T24 = Last<[symbol, ...string[]]>;
346
- type T25 = Last<string[]>;
347
- type T26 = Last<[]>; // unknown[], maybe should be []
348
- type T27 = Last<any>; // unknown, maybe should be any
349
- type T28 = Last<never>;
347
+ type T25 = Last<[string?]>;
348
+ type T26 = Last<string[]>;
349
+ type T27 = Last<[]>; // unknown, maybe should undefined
350
+ type T28 = Last<any>; // unknown, maybe should be any
351
+ type T29 = Last<never>;
350
352
351
353
type T30 = DropLast<[number, symbol, string]>;
352
354
type T31 = DropLast<[symbol, string]>;
353
355
type T32 = DropLast<[string]>;
354
356
type T33 = DropLast<[number, symbol, ...string[]]>;
355
357
type T34 = DropLast<[symbol, ...string[]]>;
356
- type T35 = DropLast<string[]>;
357
- type T36 = DropLast<[]>; // unknown[], maybe should be []
358
- type T37 = DropLast<any>;
359
- type T38 = DropLast<never>;
358
+ type T35 = DropLast<[string?]>;
359
+ type T36 = DropLast<string[]>;
360
+ type T37 = DropLast<[]>; // unknown[], maybe should be []
361
+ type T38 = DropLast<any>;
362
+ type T39 = DropLast<never>;
360
363
361
364
type R00 = First<readonly [number, symbol, string]>;
362
365
type R01 = First<readonly [symbol, string]>;
@@ -428,6 +431,15 @@ tests/cases/conformance/types/tuple/variadicTuples1.ts(342,19): error TS2322: Ty
428
431
curry2(fn10, ['hello', 42], [true]);
429
432
curry2(fn10, ['hello'], [42, true]);
430
433
434
+ // Inference to [...T] has higher priority than inference to [...T, number?]
435
+
436
+ declare function ft<T extends unknown[]>(t1: [...T], t2: [...T, number?]): T;
437
+
438
+ ft([1, 2, 3], [1, 2, 3]);
439
+ ft([1, 2], [1, 2, 3]);
440
+ ft(['a', 'b'], ['c', 'd'])
441
+ ft(['a', 'b'], ['c', 'd', 42])
442
+
431
443
// Last argument is contextually typed
432
444
433
445
declare function call<T extends unknown[], R>(...args: [...T, (...args: T) => R]): [T, R];
@@ -447,12 +459,10 @@ tests/cases/conformance/types/tuple/variadicTuples1.ts(342,19): error TS2322: Ty
447
459
448
460
function f21<U extends string[]>(args: [...U, number?]) {
449
461
let v1 = f20(args); // U
450
- let v2 = f20(["foo", "bar"]); // []
451
- ~~~~~
452
- !!! error TS2322: Type 'string' is not assignable to type 'number | undefined'.
453
- let v3 = f20(["foo", 42]); // []
454
- ~~~~~
462
+ let v2 = f20(["foo", "bar"]); // [string]
463
+ ~~~~~
455
464
!!! error TS2322: Type 'string' is not assignable to type 'number | undefined'.
465
+ let v3 = f20(["foo", 42]); // [string]
456
466
}
457
467
458
468
declare function f22<T extends unknown[] = []>(args: [...T, number]): T;
0 commit comments