1//// [variadicTuples2.ts] 2// Declarations 3 4type V00 = [number, ...string[]]; 5type V01 = [...string[], number]; 6type V03 = [number, ...string[], number]; 7 8type V10 = [number, ...string[], ...boolean[]]; // Error 9type V11 = [number, ...string[], boolean?]; // Error 10type V12 = [number, string?, boolean]; // Error 11 12// Normalization 13 14type Tup3<T extends unknown[], U extends unknown[], V extends unknown[]> = [...T, ...U, ...V]; 15 16type V20 = Tup3<[number], string[], [number]>; // [number, ...string[], number] 17type V21 = Tup3<[number], [string?], [boolean]>; // [number, string | undefined, boolean] 18type V22 = Tup3<[number], string[], boolean[]>; // [number, (string | boolean)[]] 19type V23 = Tup3<[number], string[], [boolean?]>; // [number, (string | boolean | undefined)[]] 20type V24 = Tup3<[number], [boolean?], string[]>; // [number, boolean?, ...string[]] 21type V25 = Tup3<string[], number[], boolean[]>; // (string | number | boolean)[] 22type V26 = Tup3<string[], number[], [boolean]>; // [...(string | number)[], boolean] 23type V27 = Tup3<[number?], [string], [boolean?]>; // [number | undefined, string, boolean?] 24 25type V30<A extends unknown[]> = Tup3<A, string[], number[]>; // [...A, ...(string | number)[]] 26type V31<A extends unknown[]> = Tup3<string[], A, number[]>; // (string | number | A[number])[] 27type V32<A extends unknown[]> = Tup3<string[], number[], A>; // [...(string | number)[], ...A] 28 29type V40<A extends unknown[]> = Tup3<A, [string?], number[]>; // [...A, string?, ...number[]] 30type V41<A extends unknown[]> = Tup3<[string?], A, number[]>; // [string?, ...A, ...number[]] 31type V42<A extends unknown[]> = Tup3<[string?], number[], A>; // [string?, ...number[], ...A] 32 33type V50<A extends unknown[]> = Tup3<A, string[], [number?]>; // [...A, ...(string | number | undefined)[]] 34type V51<A extends unknown[]> = Tup3<string[], A, [number?]>; // (string | number | A[number] | undefined)[] 35type V52<A extends unknown[]> = Tup3<string[], [number?], A>; // [...(string | number | undefined)[], ...A] 36 37// Assignability 38 39declare let tt1: [...string[], number]; 40tt1 = [5]; 41tt1 = ['abc', 5]; 42tt1 = ['abc', 'def', 5]; 43tt1 = ['abc', 'def', 5, 6]; // Error 44 45declare function ft1(...args: [...strs: string[], num: number]): void; 46ft1(5); 47ft1('abc', 5); 48ft1('abc', 'def', 5); 49ft1('abc', 'def', 5, 6); // Error 50 51declare let tt2: [number, ...string[], number]; 52tt2 = [0]; // Error 53tt2 = [0, 1]; 54tt2 = [0, 1, 2]; // Error 55tt2 = [0, 'abc', 1]; 56tt2 = [0, 'abc', 'def', 1]; 57tt2 = [0, 'abc', 1, 'def']; // Error 58tt2 = [true, 'abc', 'def', 1]; // Error 59tt2 = [0, 'abc', 'def', true]; // Error 60 61declare function ft2(n1: number, ...rest: [...strs: string[], n2: number]): void; 62ft2(0); // Error 63ft2(0, 1); 64ft2(0, 1, 2); // Error 65ft2(0, 'abc', 1); 66ft2(0, 'abc', 'def', 1); 67ft2(0, 'abc', 1, 'def'); // Error 68ft2(true, 'abc', 'def', 1); // Error 69ft2(0, 'abc', 'def', true); // Error 70 71function ft3<T extends unknown[]>(x: [number, ...T], y: [number, number], z: [number, ...number[]]) { 72 x = y; // Error 73 x = z; // Error 74 y = x; // Error 75 z = x; // Error 76} 77 78// Inference 79 80function pipe<T extends readonly unknown[]>(...args: [...T, (...values: T) => void]) { 81 const callback = args[args.length - 1] as (...values: T) => void; 82 const values = args.slice(0, -1) as unknown as T; 83 callback(...values); 84} 85 86pipe("foo", 123, true, (a, b, c) => { 87 a; // string 88 b; // number 89 c; // boolean 90}) 91 92pipe("foo", 123, true, (...x) => { 93 x; // [string, number, boolean] 94}); 95 96declare const sa: string[]; 97 98pipe(...sa, (...x) => { 99 x; // string[] 100}); 101 102pipe(1, ...sa, 2, (...x) => { 103 x; // [number, ...string[], number] 104 let qq = x[x.length - 1]; 105 let ww = x[0] 106}); 107 108pipe<number[]>(1, 2, 3, 4); // Error 109pipe(...sa); // Error 110 111declare function fn1<T, U>(t: [...unknown[], T, U]): [T, U]; 112fn1([]); // Error 113fn1([1]); // Error 114fn1([1, 'abc']); // [number, string] 115fn1([1, 'abc', true]); // [string, boolean] 116 117declare function fn2<T, U>(t: [T, ...unknown[], U]): [T, U]; 118fn2([]); // Error 119fn2([1]); // Error 120fn2([1, 'abc']); // [number, string] 121fn2([1, 'abc', true]); // [number, boolean] 122 123// Repro from #39595 124 125declare function foo<S extends readonly [string, ...string[]]>(...stringsAndNumber: readonly [...S, number]): [...S, number]; 126 127const a1 = foo('blah1', 1); 128const b1 = foo('blah1', 'blah2', 1); 129const c1 = foo(1); // Error 130const d1 = foo(1, 2); // Error 131const e1 = foo('blah1', 'blah2', 1, 2, 3); // Error 132 133 134//// [variadicTuples2.js] 135"use strict"; 136// Declarations 137var __spreadArray = (this && this.__spreadArray) || function (to, from) { 138 for (var i = 0, il = from.length, j = to.length; i < il; i++, j++) 139 to[j] = from[i]; 140 return to; 141}; 142tt1 = [5]; 143tt1 = ['abc', 5]; 144tt1 = ['abc', 'def', 5]; 145tt1 = ['abc', 'def', 5, 6]; // Error 146ft1(5); 147ft1('abc', 5); 148ft1('abc', 'def', 5); 149ft1('abc', 'def', 5, 6); // Error 150tt2 = [0]; // Error 151tt2 = [0, 1]; 152tt2 = [0, 1, 2]; // Error 153tt2 = [0, 'abc', 1]; 154tt2 = [0, 'abc', 'def', 1]; 155tt2 = [0, 'abc', 1, 'def']; // Error 156tt2 = [true, 'abc', 'def', 1]; // Error 157tt2 = [0, 'abc', 'def', true]; // Error 158ft2(0); // Error 159ft2(0, 1); 160ft2(0, 1, 2); // Error 161ft2(0, 'abc', 1); 162ft2(0, 'abc', 'def', 1); 163ft2(0, 'abc', 1, 'def'); // Error 164ft2(true, 'abc', 'def', 1); // Error 165ft2(0, 'abc', 'def', true); // Error 166function ft3(x, y, z) { 167 x = y; // Error 168 x = z; // Error 169 y = x; // Error 170 z = x; // Error 171} 172// Inference 173function pipe() { 174 var args = []; 175 for (var _i = 0; _i < arguments.length; _i++) { 176 args[_i] = arguments[_i]; 177 } 178 var callback = args[args.length - 1]; 179 var values = args.slice(0, -1); 180 callback.apply(void 0, values); 181} 182pipe("foo", 123, true, function (a, b, c) { 183 a; // string 184 b; // number 185 c; // boolean 186}); 187pipe("foo", 123, true, function () { 188 var x = []; 189 for (var _i = 0; _i < arguments.length; _i++) { 190 x[_i] = arguments[_i]; 191 } 192 x; // [string, number, boolean] 193}); 194pipe.apply(void 0, __spreadArray(__spreadArray([], sa), [function () { 195 var x = []; 196 for (var _i = 0; _i < arguments.length; _i++) { 197 x[_i] = arguments[_i]; 198 } 199 x; // string[] 200 }])); 201pipe.apply(void 0, __spreadArray(__spreadArray([1], sa), [2, function () { 202 var x = []; 203 for (var _i = 0; _i < arguments.length; _i++) { 204 x[_i] = arguments[_i]; 205 } 206 x; // [number, ...string[], number] 207 var qq = x[x.length - 1]; 208 var ww = x[0]; 209 }])); 210pipe(1, 2, 3, 4); // Error 211pipe.apply(void 0, sa); // Error 212fn1([]); // Error 213fn1([1]); // Error 214fn1([1, 'abc']); // [number, string] 215fn1([1, 'abc', true]); // [string, boolean] 216fn2([]); // Error 217fn2([1]); // Error 218fn2([1, 'abc']); // [number, string] 219fn2([1, 'abc', true]); // [number, boolean] 220var a1 = foo('blah1', 1); 221var b1 = foo('blah1', 'blah2', 1); 222var c1 = foo(1); // Error 223var d1 = foo(1, 2); // Error 224var e1 = foo('blah1', 'blah2', 1, 2, 3); // Error 225 226 227//// [variadicTuples2.d.ts] 228declare type V00 = [number, ...string[]]; 229declare type V01 = [...string[], number]; 230declare type V03 = [number, ...string[], number]; 231declare type V10 = [number, ...string[], ...boolean[]]; 232declare type V11 = [number, ...string[], boolean?]; 233declare type V12 = [number, string?, boolean]; 234declare type Tup3<T extends unknown[], U extends unknown[], V extends unknown[]> = [...T, ...U, ...V]; 235declare type V20 = Tup3<[number], string[], [number]>; 236declare type V21 = Tup3<[number], [string?], [boolean]>; 237declare type V22 = Tup3<[number], string[], boolean[]>; 238declare type V23 = Tup3<[number], string[], [boolean?]>; 239declare type V24 = Tup3<[number], [boolean?], string[]>; 240declare type V25 = Tup3<string[], number[], boolean[]>; 241declare type V26 = Tup3<string[], number[], [boolean]>; 242declare type V27 = Tup3<[number?], [string], [boolean?]>; 243declare type V30<A extends unknown[]> = Tup3<A, string[], number[]>; 244declare type V31<A extends unknown[]> = Tup3<string[], A, number[]>; 245declare type V32<A extends unknown[]> = Tup3<string[], number[], A>; 246declare type V40<A extends unknown[]> = Tup3<A, [string?], number[]>; 247declare type V41<A extends unknown[]> = Tup3<[string?], A, number[]>; 248declare type V42<A extends unknown[]> = Tup3<[string?], number[], A>; 249declare type V50<A extends unknown[]> = Tup3<A, string[], [number?]>; 250declare type V51<A extends unknown[]> = Tup3<string[], A, [number?]>; 251declare type V52<A extends unknown[]> = Tup3<string[], [number?], A>; 252declare let tt1: [...string[], number]; 253declare function ft1(...args: [...strs: string[], num: number]): void; 254declare let tt2: [number, ...string[], number]; 255declare function ft2(n1: number, ...rest: [...strs: string[], n2: number]): void; 256declare function ft3<T extends unknown[]>(x: [number, ...T], y: [number, number], z: [number, ...number[]]): void; 257declare function pipe<T extends readonly unknown[]>(...args: [...T, (...values: T) => void]): void; 258declare const sa: string[]; 259declare function fn1<T, U>(t: [...unknown[], T, U]): [T, U]; 260declare function fn2<T, U>(t: [T, ...unknown[], U]): [T, U]; 261declare function foo<S extends readonly [string, ...string[]]>(...stringsAndNumber: readonly [...S, number]): [...S, number]; 262declare const a1: ["blah1", number]; 263declare const b1: ["blah1", "blah2", number]; 264declare const c1: [string, ...string[], number]; 265declare const d1: [string, ...string[], number]; 266declare const e1: [string, ...string[], number]; 267