@@ -39,12 +39,11 @@ tests/cases/conformance/types/tuple/variadicTuples1.ts(191,5): error TS2322: Typ
3939 'U' could be instantiated with an arbitrary type which could be unrelated to 'readonly string[]'.
4040tests/cases/conformance/types/tuple/variadicTuples1.ts(203,5): error TS2322: Type 'string' is not assignable to type 'keyof [1, 2, ...T]'.
4141 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'.
4544
4645
47- ==== tests/cases/conformance/types/tuple/variadicTuples1.ts (21 errors) ====
46+ ==== tests/cases/conformance/types/tuple/variadicTuples1.ts (20 errors) ====
4847 // Variadics in tuple types
4948
5049 type TV0<T extends unknown[]> = [string, ...T];
@@ -313,50 +312,54 @@ tests/cases/conformance/types/tuple/variadicTuples1.ts(342,19): error TS2322: Ty
313312 // Inference between variadic tuple types
314313
315314 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];
317316
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];
320319
321320 type T00 = First<[number, symbol, string]>;
322321 type T01 = First<[symbol, string]>;
323322 type T02 = First<[string]>;
324323 type T03 = First<[number, symbol, ...string[]]>;
325324 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>;
330330
331331 type T10 = DropFirst<[number, symbol, string]>;
332332 type T11 = DropFirst<[symbol, string]>;
333333 type T12 = DropFirst<[string]>;
334334 type T13 = DropFirst<[number, symbol, ...string[]]>;
335335 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>;
340341
341342 type T20 = Last<[number, symbol, string]>;
342343 type T21 = Last<[symbol, string]>;
343344 type T22 = Last<[string]>;
344345 type T23 = Last<[number, symbol, ...string[]]>;
345346 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>;
350352
351353 type T30 = DropLast<[number, symbol, string]>;
352354 type T31 = DropLast<[symbol, string]>;
353355 type T32 = DropLast<[string]>;
354356 type T33 = DropLast<[number, symbol, ...string[]]>;
355357 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>;
360363
361364 type R00 = First<readonly [number, symbol, string]>;
362365 type R01 = First<readonly [symbol, string]>;
@@ -428,6 +431,15 @@ tests/cases/conformance/types/tuple/variadicTuples1.ts(342,19): error TS2322: Ty
428431 curry2(fn10, ['hello', 42], [true]);
429432 curry2(fn10, ['hello'], [42, true]);
430433
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+
431443 // Last argument is contextually typed
432444
433445 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
447459
448460 function f21<U extends string[]>(args: [...U, number?]) {
449461 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+ ~~~~~
455464!!! error TS2322: Type 'string' is not assignable to type 'number | undefined'.
465+ let v3 = f20(["foo", 42]); // [string]
456466 }
457467
458468 declare function f22<T extends unknown[] = []>(args: [...T, number]): T;
0 commit comments